Guess the number/With feedback: Difference between revisions

Line 717:
=={{header|Ela}}==
 
<lang ela>open string datetime random core console string datetimemonad readio
 
guess () = do
rnd' v = rnd s 1 v where s = milliseconds <| datetime.now()
putStrLn "What's the upper bound?"
ub <- readAny
start () =
main ub
match bound() with
where main ub
Some v = writen ("Guess a number from 1 to " ++ show v) `seq` (guess <| rnd' v)
None| ub < 0 = start()"Bound should be greater than 0."
| else = do
putStrLn $ format "Guess a number from 1 to {0}" ub
bound () =
rnd' v = rnd s 1 v where s = milliseconds dt <|- datetime.now()
writen "What's the upper bound?" `seq` (bound' <| readStr <| readn())
where bound' v | v <= 0 = writen "Bound shouldguesser be(rnd greater(milliseconds than$ 0."dt) `seq`1 Noneub)
guesser | else v = Some vdo
x <- readAny
if x == v then
success v =
writen "Correct! Do you want to continue? (Y/N)" `seq` ask cont ()
where ask () = read <| upper else if x <| readn()v then
read "Y" = start() do putStrLn "Too small!"
read "N" = writen "Bye!" guesser v
read x else = writen "Say what?" `seq` ask()
do putStrLn "Too big!"
guesser v
failed v n =
cont () = do
writen ("No, this is not " ++ show v ++ ". " ++ hint) `seq` guess n
putStrLn "Correct! Do you wish to continue (Y/N)?"
where hint | v < n = "Try bigger."
ask | else = "Try smaller."()
ask () = do
guess n = g <| readStr a <|- readn()readStr
where g v | v if a == n"y" || a == success"Y" vthen
|guess else = failed v n()
else if a == "n" || a == "N" then
do putStrLn "Bye!"
start()</lang>
else
do putStrLn "Say what?"
ask ()
 
startguess () ::: IO</lang>
 
=={{header|Elixir}}==
Anonymous user