/* amoeba.tc - tct - 6/20/9, 7/8/9 amoeba [ pl "" hilo '1';color '4';ps "amoeba.tc - tct - 7/8/9";pl "" pl "An amoeba either dies, lives, splits into two or splits into three," pl "each with probability 1/4. It can be proved that, out of 100 simulations," pl "about 100*(sqrt(2)-1), which equals about 41.4, populations will die out." pl "It can also be proved that 1.5^n is the expected number of amoebas" pl "after n generations. If n=30, 191751 amoebas are expected. If n=10," pl "58 amoebas are expected." pl "" pl "Note: The Linux version of the tiny-c interpreter can handle 20+" pl "generations. The DOS version can do at most 13 generations." pl "" pl "Ref: http://yofx.blogspot.com/2009/06/amoeba-fever-problem.html" int c,p,pp,r,psp,g,s int sn,n,ptot /* n tracks generation, ptot tracks population count color '7';pl "";pl "seed? ";seed=last=gn ps "generations (e.g. 10 or 30)? ";sn=gn s=4 /* number of "runs" + 1 while (--s) [ /* 1 c=0;g=100;ptot=0 /* g is number of "simulations" in a "run" while (--g) [ /* 2 p=psp=1 n=sn+1 while (--n*psp) [ /* 3 for (pp=1;pp<=p;++pp) psp=psp+random(1,4)-2 p=psp;if (!p) ++c ] /* 3 ptot=ptot+p ] /* 2 pl "";ps "Simulation #";pn 4-s;ps ".";pn c;ps " populations died out." pl "";pn ptot/100;ps " amoebas, on average, were living after" pn sn;ps " generations.";pl "" ] /* 1 hilo '0' ]