Skip to content

Instantly share code, notes, and snippets.

@specdrake
Last active May 30, 2020 18:00
Show Gist options
  • Save specdrake/19af8d914f944b1960e48bdb83bc109e to your computer and use it in GitHub Desktop.
Save specdrake/19af8d914f944b1960e48bdb83bc109e to your computer and use it in GitHub Desktop.
module Main where
main :: IO ()
main = do
guessI <- getLine
if (read guessI /= 0) then
oneGame True (read guessI) (1, 10)
else
return ()
oneGame :: Bool -> Int -> (Int, Int) -> IO ()
oneGame isHon g (a, b)= do
guessCmt <- getLine
if (guessCmt == "too high")
then if (g == a)
then getGuess False (a, g)
else getGuess isHon (a,g-1)
else if (guessCmt == "too low")
then if (g==b)
then getGuess False (g, b)
else getGuess isHon (g+1, b)
else if (guessCmt == "right on")
then if (g `elem` [a..b] && isHon)
then putStrLn "Stan may be honest" >> main
else putStrLn "Stan is dishonest" >> main
else main
getGuess :: Bool -> (Int, Int) -> IO ()
getGuess isHon tup = do
guessI <- getLine
if (read guessI /= 0) then
oneGame isHon (read guessI) tup
else
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment