You are viewing a single comment's thread. Return to all comments →
import Control.Monad import Data.List (isPrefixOf)
main :: IO () main = readLn >>= flip replicateM_ testCase
testCase :: IO () testCase = do _ <- getLine passwords <- fmap words getLine guess <- getLine case sequence (loginAttempt passwords guess) of Nothing -> putStrLn "WRONG PASSWORD" Just xs -> putStrLn $ unwords xs
loginAttempt :: [String] -> String -> [Maybe String] loginAttempt _ [] = [] loginAttempt passwords guess = case matching of [] -> [Nothing] (x:_) -> Just x : loginAttempt passwords (drop (length x) guess) where matching = filter (flip isPrefixOf guess) passwords
Seems like cookies are disabled on this browser, please enable them to open this website
Password Cracker FP
You are viewing a single comment's thread. Return to all comments →
import Control.Monad import Data.List (isPrefixOf)
main :: IO () main = readLn >>= flip replicateM_ testCase
testCase :: IO () testCase = do _ <- getLine passwords <- fmap words getLine guess <- getLine case sequence (loginAttempt passwords guess) of Nothing -> putStrLn "WRONG PASSWORD" Just xs -> putStrLn $ unwords xs
loginAttempt :: [String] -> String -> [Maybe String] loginAttempt _ [] = [] loginAttempt passwords guess = case matching of [] -> [Nothing] (x:_) -> Just x : loginAttempt passwords (drop (length x) guess) where matching = filter (flip isPrefixOf guess) passwords