Download or view organisms.frink in plain text format
/**
A puzzle from Robin Houston:
Someone posted a really nice mathematical question on work slack.
We have a population of independent single-called organisms in a dish. At
each generation, each of them:
• with probability 0.4, dies
• otherwise, divides into twon
Initially the population is 1. What is the probability that the colony eventually becomes extinct?
https://twitter.com/robinhouston/status/1565622812924121088
*/
trials = million
gens = 15
alive = 0
largestDead = 0
TRIAL:
for count = 1 to trials
{
largest = 0
p = 1
GEN:
for gen = 1 to gens
{
if p > largest
largest = p
if p == 0
{
if largest > largestDead
largestDead = largest
next TRIAL
}
pnew = 0
for n = 0 to p-1
{
if randomFloat[0,1] > 0.4
pnew = pnew + 2
}
// println["$gen $pnew"]
p = pnew
}
alive = alive + 1
}
println["$alive out of $trials"]
println["Probability of extinction is " + (1 - (alive/trials))]
println["Largest dead is $largestDead"]
Download or view organisms.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 was born 20139 days, 6 hours, 12 minutes ago.