Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Reader
--ghc 7.10 import System.Random main = print $ "Hello, world!" data Die = DieOne | DieTwo | DieThree | DieFour | DirFive | DieSix deriving (Show, Eq) intToDue :: Int -> Die intToDie n = case n of 1 -> DieOne 2 -> DieTwo 3 -> DieThree 4 -> DieFour 5 -> DieFive 6 -> DieSix x -> error $ "intToDie got non 1-6 integer: " ++ show x rollDie :: State StdGen Die rollDie = state $ do (n, s) <- randomR (1, 6) return (intToDie n, s) rollDie' = intToDie <$> state (randomR (1, 6)) rollDieThreeTimes :: State StdGen (Die, Die, Die) rollDieThreeTimes = liftA3 (,,) rollDie rollDie rollDie rollsToGetTwenty :: StdGen -> Int rollsToGetTwenty g = go 0 0 g where go :: Int -> Int -> StdGen -> Int go sum count gen | sum >= 20 = count | otherwise = let (die, nextGen) = randomR (1, 6) gen in go (sum + die) (count + 1) nextGen
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Anonymous recursion. Why doesnt compile?
Test
appending and prepending list
NQueens
znajdywacz trojkatow prostokatnych
ReadablePractice
credit card number validator
suffix trie
(-‿‿-)
Znajdz trójkąty prostokątne
stackse - search stackoverflow differently
Please log in to post a comment.