Download or view MandMdistribution.frink in plain text format
/** 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 a randomized simulation that runs for a large number of trials to
find "probably about right" numbers.
*/
trials = 10 million
pieces = 300
distros = new dict
for trial = 1 to trials
{
pack = new dict
for n = 1 to pieces
pack.increment[random[0,5]]
sorted = reverse[sort[getColumn[toArray[pack], 1]]]
distros.increment[sorted]
}
println["Sorting."]
for [dist, count] = sort[distros, byColumn[1]]
{
centered = subtract[dist,50]
println["$dist\t$centered\t$count"]
}
Download or view MandMdistribution.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen, eliasen@mindspring.com