* Coin Toss simulation * A fair coin is tossed repeatedly, until one of two patterns appears. * The pattern determines the winner of the game. * Games are played repeatedly up to LIM games. * Performance of each pattern is determined based on number of games won, * .. and on the average number of tosses required to win, for each pattern. * NOTE: This program was developed during lunch at work, on a proprietary database platform using the * .. language "Pick Basic".. No compiled version is available for standard desktop systems. * A screen dump of the output is provided in a separate text file. * CES 512 - D. Bozarth - 17 Feb 2005 * equ LIM to 100000 AM = char(254) score1 = 0 ; score2 = 0 toss1 = 0 ; toss2 = 0 * for j = 1 to LIM gosub PLAY next j * crt crt 'Number games = ':LIM'r#8' crt crt 'First player ' crt space(4):'games won = ':score1'r#8' crt space(4):'avg. tosses to win = ':oconv((toss1 * 100 / score1), 'mr2')'r#5' crt crt 'Second player ' crt space(4):'games won = ':score2'r#8' crt space(4):'avg. tosses to win = ':oconv((toss2 * 100 / score2), 'mr2')'r#5' crt stop * PLAY: toss = 0 seq = '' loop toss += 1 gosub TOSS gosub CHECK begin case case won eq 1 score1 += 1 toss1 += toss return case won eq 2 score2 += 1 toss2 += toss return end case repeat return * TOSS: r = rnd(99) + 1 if r < 51 then val = '1' ;* Heads end else val = '0' ;* Tails end seq<-1> = val return * CHECK: won = 0 i = dcount(seq, AM) if i > 2 then begin case case not(seq) and not(seq) and seq ;* TTH won = 1 case not(seq) and seq and not(seq) ;* THT won = 2 end case end return