Created
November 23, 2012 20:08
-
-
Save davidsantiago/4137077 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 Data.ByteString.Lazy as BSL | |
import Data.ByteString.Lazy.Char8 as BSC | |
import Data.Set as Set | |
tlds :: Set ByteString | |
tlds = Set.map BSC.pack $ Set.fromList ["biz", "bz", "cc", | |
"co", "com", "es", "info", | |
"io", "me", "net", "org", | |
"pro", "tv", "us", "ws"] | |
dropPrefix prefix word = BSC.drop (BSC.length prefix) word | |
coword prefix word = append (dropPrefix prefix word) | |
prefix | |
coWords dict word = | |
let prefixes = Set.filter (`isPrefixOf` word) tlds | |
in | |
Set.filter (\pre -> (member (dropPrefix pre word) dict) | |
|| (member (coword pre word) dict)) | |
prefixes | |
main = do file <- BSL.readFile "/usr/share/dict/words" | |
let dict = Set.fromList $ BSC.words file | |
let wordsWithCowords = Set.filter (\x -> (coWords dict x) /= Set.empty) dict | |
print $ Set.map BSC.unpack wordsWithCowords |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment