Skip to content

Instantly share code, notes, and snippets.

@sadhu89
Created October 2, 2016 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sadhu89/0fbd96ea61fa5b74579ba73d68ccdd2d to your computer and use it in GitHub Desktop.
Save sadhu89/0fbd96ea61fa5b74579ba73d68ccdd2d to your computer and use it in GitHub Desktop.
check :: String -> String -> Char -> (Bool, String)
check word display c
= ( c `elem` word, [if x == c
then c
else y | (x,y) <- zip word display])
turn :: String -> String -> Int -> IO ()
turn word display n =
do if n == 0
then putStrLn "You lose"
else if word == display
then putStrLn "You win!"
else mkguess word display n
mkguess :: String -> String -> Int -> IO ()
mkguess word display n =
do putStrLn (display ++ " " ++ take n (repeat '*'))
putStr " Enter your guess: "
q <- getLine
let (correct, display') = check word display (q!!0)
let n' = if correct then n else n-1
turn word display' n'
starman :: String -> Int -> IO ()
starman word n = turn word ['-' | x <- word] n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment