All pastes #773542 Raw Edit

Untitled

public text v1 · immutable
·published 2007-11-14 16:40 UTC
rendered paste body
import Data.Char
import Control.Applicative

main = do
   s <- lines <$> readFile "/usr/share/dict/web2"
   putStr "enter length of word: "
   n <- read <$> getLine
   let words = filter (\x -> length x == n) s
   putStrLn (show(length words)    " possibilites")
   putStr "enter first letter of word: "
   a <- head <$> getLine
   let words2 = filter (\x -> head x == a) words
   putStrLn (show(length words2)    " possibilites")
   putStr "enter last letter of word: "
   b <- head <$> getLine
   let words3 = filter (\x -> last x == b) words2
   putStrLn (show(length words3)    " possibilites")
   isWord words3 0

isWord (w:ws) i = do
   putStr ("is the word "    w    "?: ")
   r <- toLower . head <$> getLine
   if (r == 'y')
       then putStrLn "HA! Told you I was smart!"
       else if (i == 10)
           then putStrLn "You outwitted me!"
           else isWord ws (i 1)