Skip to content

Instantly share code, notes, and snippets.

@jonathanlking
Created September 14, 2015 14:04
Show Gist options
  • Save jonathanlking/87e5b2b9f600d0e0888e to your computer and use it in GitHub Desktop.
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.
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