Created
September 14, 2015 14:04
-
-
Save jonathanlking/87e5b2b9f600d0e0888e to your computer and use it in GitHub Desktop.
Calculates the possible numbers that could be thrown by `n` dice, and the number of occurrences.
This file contains 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 | |
import Control.Arrow | |
import Data.List | |
dice :: Int -> [(Int, Int)] | |
dice = freq . map sum . (flip replicateM) [1..6] | |
freq :: Ord a => [a] -> [(a, Int)] | |
freq = map (head &&& length) . group . sort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment