Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,16 @@
import Control.Monad
import System.Random
-- Repeat the action until the predicate is true.
until_ act pred = act >>= pred >>= flip unless (until_ act pred)
answerIs ans guess
| ans == guess = putStrLn "You got it!" >> return True
| otherwise = putStrLn "Nope. Guess again." >> return False
ask = liftM read getLine
main = do
ans <- randomRIO (1,10) :: IO Int
putStrLn "Try to guess my secret number between 1 and 10."
ask `until_` answerIs ans

View file

@ -0,0 +1,10 @@
import System.Random
main = randomRIO (1,10) >>= gameloop
gameloop :: Int -> IO ()
gameloop r = do
i <- fmap read getLine
if i == r
then putStrLn "You got it!"
else putStrLn "Nope. Guess again." >> gameloop r