Created
February 13, 2015 17:07
-
-
Save JDevlieghere/2e6c30e2b57ada6c6bae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
toSet :: ByteString -> Set ByteString | |
toSet = Set.fromList . B.words . B.map toLower | |
toWords :: ByteString -> [ByteString] | |
toWords s | |
| B.null s = [] | |
| otherwise = B.inits s ++ toWords (B.tail s) | |
solve :: Set ByteString -> [ByteString] -> [ByteString] | |
solve dict strs = filter valid wrds | |
where wrds = foldr ((++) . toWords) [] strs | |
valid w = B.length w > 3 && Set.member w dict | |
main :: IO () | |
main = do | |
(dfile:ifile:_) <- getArgs | |
dictionary <- B.readFile dfile | |
input <- B.readFile ifile | |
let dict = toSet dictionary | |
rows = (B.lines . B.map toLower) input | |
cols = B.transpose rows | |
solutions = solve dict (rows ++ cols) `using` parList rseq | |
putStrLn $ B.unpack $ B.unlines solutions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment