/** Puzzle from Matthew Roozee: Suppose there are exactly 300 m&m’s total in a bag and each one is randomly determined to be one of the six colors (all equally likely). What is the most likely distribution of m&m’s? This is an exact solver for probabilities. */ use statistics.frink bagSize = 300 colors = 6 showApproximations[false] for [p,n] = partitionsOfSize[bagSize, colors, true] { prob = n remain = bagSize for d = colors to 1 step -1 { k = p@(colors-d) prob = prob * binomialDensity[k, remain, 1/d] remain = remain-k } println[formatSci[prob,1,15] + "\t$n\t$p"] }