Created
February 17, 2015 22:33
-
-
Save stephenmac7/a4e3539f2925d3d228ef to your computer and use it in GitHub Desktop.
Word filter to create fancy polyatomic ion mnemonics (http://www2.ucdsb.on.ca/tiss/stretton/database/Mneumonics.html)
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
import System.Environment (getArgs) | |
import Data.List (isPrefixOf, partition) | |
import Data.Char (toLower) | |
checkWord :: String -> Int -> Int -> String -> Bool | |
checkWord begin vowels consonants s = isPrefixOf begin s && vowels == vCount && consonants == cCount | |
where isVowel = flip elem "aeiou" | |
(vCount, cCount) = let (vs, cs) = partition isVowel s in (length vs, length cs) | |
main = do | |
f <- readFile "wordsEn.txt" | |
begin:nVowels:nConsonants:[] <- getArgs | |
let matches = filter (checkWord (map toLower begin) (read nVowels) (read nConsonants)) (lines f) | |
putStrLn $ show (length matches) ++ " matches:\n--------------" | |
mapM_ putStrLn matches |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment