Created
November 4, 2019 16:17
-
-
Save jeovazero/baebab4e0f68f372870d1fda763906bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.Set as Set | |
fInput [] = [] | |
fInput (_:b:c:others) = | |
(words b, c):fInput others | |
solve' _ target [] ans | |
| target /= [] = [] | |
| otherwise = ans | |
solve' dict target (p:ps) ans = | |
let | |
ntgt = (target ++ [p]) | |
btgt = Set.member ntgt dict | |
in | |
case btgt of | |
True -> | |
solve' dict [] ps (ntgt:ans) | |
False -> | |
solve' dict ntgt ps ans | |
solve (ws, pass) = | |
let | |
dict = Set.fromList ws | |
ans = (solve' dict [] pass []) | |
in | |
case ans of | |
[] -> "WRONG PASSWORD" | |
_ -> unwords (reverse ans) | |
main = do | |
interact $ unlines . fmap solve . fInput . tail . lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment