#include #include #include #include /* amoeba.c - lrb - 9/25/12 An amoeba either dies, lives, splits into two or splits into three, each with probability 1/4. It can be proved that (1.5)^n is the expected number of amoebas after n generations and that a family tree becomes extinct about 41.4 percent of the time. Starting w/ 1 amoeba, we let the amoebas split for up to the specified number of generations. Ref: http://primepuzzle.com/tc/amoeba.html */ static int rnd_seed; int rand_int() { unsigned int hi,lo; hi=16807*(rnd_seed>>16); lo=16807*(rnd_seed&0xFFFF); lo+=(hi&0x7FFF)<<16; lo+=hi>>15; if (lo>2147483647) lo-=2147483647; rnd_seed=lo; return rnd_seed; } void usage() { printf("\namoeba.c - lrb - 9/25/2012"); printf("\nUsage: amoeba [-b] [-g generations] [-s simulations] [-r rseed]\n"); exit(1); } int main(int argc,char *argv[]) { unsigned int i,c,p,pp,psp,s,sims=10,gens=10,n,ptot,b=0; rnd_seed=101; for (i=1;i