Created
March 10, 2016 14:12
-
-
Save jakab922/19ac7d93f447853ebc9d 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
import Control.Monad.State | |
import System.Random | |
import Data.List | |
import System.Environment | |
rollDie :: State StdGen Int | |
rollDie = state $ randomR (1, 6) -- randomR (1, 6) :: StdGen -> (Int, StdGen) | |
rollNDice :: Int -> State StdGen [Int] | |
rollNDice x | x < 1 = return [] | |
| otherwise = rollDie >>= (\curr -> rollNDice (x - 1) >>= (\rest -> return (curr : rest))) | |
counts :: Int -> Int -> [Int] | |
counts n seed = map length $ groupBy (==) $ sort $ evalState (rollNDice n) (mkStdGen seed) | |
main = do | |
args <- getArgs | |
n <- return . read $ args !! 0 :: IO Int | |
seed <- return . read $ args !! 1 :: IO Int | |
putStrLn $ show $ counts n seed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment