Skip to content

Instantly share code, notes, and snippets.

@Centaur
Created July 31, 2012 14:03
Show Gist options
  • Save Centaur/3217281 to your computer and use it in GitHub Desktop.
Save Centaur/3217281 to your computer and use it in GitHub Desktop.
haskell guess
askAndCompare :: Int -> Int -> IO ()
askAndCompare target level = do
putStr "Input your guess:"
hFlush stdout
input <- getLine
case compare (read input) target of
LT -> do putStrLn "Too small! Try again."
askAndCompare target (level + 1)
GT -> do putStrLn "Too Big! Try again."
askAndCompare target (level + 1)
EQ -> putStrLn $ "Bingo! You take " ++ (show level) ++ " times!"
main = do
target <- randomRIO(1, 100)
askAndCompare target 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment