/* stick.tc - 3/27/9 - tct dpf int n,d,p [ /* display proper fraction n/d as decimal number /* with p digit precision int w w=10*n/d if (p) [ MC w,14 dpf 10*n%d,d,p-1 /* recursive call ] ] int last rand [ /* returns random number in 1..2^31-1 int m;m=2147483647 int a;a=16807 last=last*a%m if (last<0) last=-last return last ] /* this was motivated by the "Sticky Probability Problem" in the Minitab manual on pg 51 /* two points along a straight stick are randomly selected. the stick is then broken at /* these two points. find the probability that the three pieces can be arranged to form /* a triangle. can be proved that p=.25 stick [ pl "";ps "stick.tc - 3/27/9 - tct";pl "";pl "" ps "seed (e.g. 315) ";last=gn;if (last%2==0) ++last /* make odd pl "number of simulations (e.g. 1, 100, 200, 2000, 15000 etc.) " int ul;ul=gn int r1,r2,s,c,j,s1,s2,s3,k for (k=1;k<=10;++k) [ c=0 for (j=1;j<=ul;++j) [ r1=(rand()+1)/2%1000000+1;r2=(rand()+1)/2%1000000+1 /* r1 and r2 are in 1..1000000 if (r1>r2) [s=r1;r1=r2;r2=s] /* r1s2) [s=s1;s1=s2;s2=s] if (s2>s3) [s=s2;s2=s3;s3=s] if (s1>s2) [s=s1;s1=s2;s2=s] /* s1<=s2<=s3 if ((s1+s2)>s3) ++c ] pl "probability of triangle =";pn c/ul;ps ".";dpf(c%ul,ul,4) ] pl "" ]