Skip to content

Instantly share code, notes, and snippets.

@jeovazero
Created November 4, 2019 16:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeovazero/baebab4e0f68f372870d1fda763906bb to your computer and use it in GitHub Desktop.
Save jeovazero/baebab4e0f68f372870d1fda763906bb to your computer and use it in GitHub Desktop.
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