Skip to content

Instantly share code, notes, and snippets.

@stephenmac7
Created February 17, 2015 22:33
Show Gist options
  • Save stephenmac7/a4e3539f2925d3d228ef to your computer and use it in GitHub Desktop.
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)
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