Skip to content

Instantly share code, notes, and snippets.

@sousatg
Created February 12, 2016 17:58
Show Gist options
  • Save sousatg/67e7336ed0d12dce24fb to your computer and use it in GitHub Desktop.
Save sousatg/67e7336ed0d12dce24fb to your computer and use it in GitHub Desktop.
The game of HILO coded in haskell
module Hilo where
import System.Random as R
jogo :: Int -> Int -> IO Int
jogo n x = do
putStr "Tentativa? "
str <- getLine
let y = read str
if y == x then
return n
else if y > x then
do
putStrLn "Demasiado alto!"
jogo (n+1) x
else
do
putStrLn "Demasiado baixo!"
jogo (n+1) x
main :: IO ()
main = do
numero <- R.randomRIO(1,100)
n <- jogo 1 numero
putStrLn ("Tentativas " ++ show(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment