Skip to content

Instantly share code, notes, and snippets.

@jakab922
Created March 10, 2016 14:12
Show Gist options
  • Save jakab922/19ac7d93f447853ebc9d to your computer and use it in GitHub Desktop.
Save jakab922/19ac7d93f447853ebc9d to your computer and use it in GitHub Desktop.
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