Skip to content

Instantly share code, notes, and snippets.

@MorrowM
Created February 7, 2024 15:29
Show Gist options
  • Save MorrowM/a5fe496cd61c4baaf3c7aa909c7e68c3 to your computer and use it in GitHub Desktop.
Save MorrowM/a5fe496cd61c4baaf3c7aa909c7e68c3 to your computer and use it in GitHub Desktop.
Sicherman Dice
{-# LANGUAGE QuasiQuotes #-}
import Data.Foldable
import Data.List
import PyF
f = ([1, 2, 2, 3, 3, 4] !!) . pred
g = ([1, 3, 4, 5, 6, 8] !!) . pred
x (i, j) = i + j
y (i, j) = f i + g j
combs fun tot = [(i, j) | i <- [1 .. 6], j <- [1 .. 6], fun (i, j) == tot]
-- >>> combs x 5
-- [(1,4),(2,3),(3,2),(4,1)]
-- >>> combs y 5
-- [(1,3),(2,2),(3,2),(6,1)]
main = do
for_ [2 .. 12] $ \tot -> do
let xCombs = combs x tot
yCombs = combs y tot
lengthX = length xCombs
lengthY = length yCombs
disp = intercalate ", " . map (show @(Int, Int))
putStrLn [fmt|\\P(X = {tot}) &= \\P(\\set{{{disp xCombs}}}) &= {lengthX}/36 \\\\\\P(Y = {tot}) &= \\P(\\set{{{disp yCombs}}}) &= {lengthY}/36 \\\\|]
-- Check that the distributions actually are the same
print $ all (\tot -> length (combs x tot) == length (combs y tot)) [2 .. 12]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment