Last active
May 30, 2020 18:00
-
-
Save specdrake/19af8d914f944b1960e48bdb83bc109e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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