Skip to content

Instantly share code, notes, and snippets.

@dpiponi
Last active July 25, 2017 21:05
Show Gist options
  • Save dpiponi/417d4d5636caebd54e96f6d2c85b2ed4 to your computer and use it in GitHub Desktop.
Save dpiponi/417d4d5636caebd54e96f6d2c85b2ed4 to your computer and use it in GitHub Desktop.
> import qualified Data.Map as M
> vowel :: Char -> Bool
> vowel 'a' = True
> vowel 'e' = True
> vowel 'i' = True
> vowel 'o' = True
> vowel 'u' = True
> vowel _ = False
> vowelStar :: String -> [String]
> vowelStar "" = []
> vowelStar (l : ls) | vowel l = ('*' : ls) : map (l :) (vowelStar ls)
> | otherwise = map (l :) (vowelStar ls)
> main = do
> h <- readFile "/usr/share/dict/words"
> let d = [(v, [u]) | u <- words h, v <- vowelStar u]
> let e = map snd $ M.toList $ M.fromListWith (++) d
> let f = filter ((== 5) . length) e
> mapM_ print f
Result is:
["u","o","i","e","a"]
["bug","bog","big","beg","bag"]
["bull","boll","bill","bell","ball"]
["bull's","boll's","bill's","bell's","ball's"]
["bulls","bolls","bills","bells","balls"]
["blunder","blonder","blinder","blender","blander"]
["fur","for","fir","fer","far"]
["lust","lost","list","lest","last"]
["muss","moss","miss","mess","mass"]
["muss's","moss's","miss's","mess's","mass's"]
["musses","mosses","misses","messes","masses"]
["mute","mote","mite","mete","mate"]
["mute's","mote's","mite's","mete's","mate's"]
["mutes","motes","mites","metes","mates"]
["puck","pock","pick","peck","pack"]
["puck's","pock's","pick's","peck's","pack's"]
["pucks","pocks","picks","pecks","packs"]
["pup","pop","pip","pep","pap"]
["pup's","pop's","pip's","pep's","pap's"]
["pups","pops","pips","peps","paps"]
["put","pot","pit","pet","pat"]
["put's","pot's","pit's","pet's","pat's"]
["puts","pots","pits","pets","pats"]
["putted","potted","pitted","petted","patted"]
["putting","potting","pitting","petting","patting"]
["tun","ton","tin","ten","tan"]
["tun's","ton's","tin's","ten's","tan's"]
["tuns","tons","tins","tens","tans"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment