Re: Gaussian Distribution Using Dice
- Posted by "Juergen Luethje" <j.lue at gmx.de> Jul 31, 2004
- 488 views
Just 2 small comments (see below). Lewis Townsend wrote: > ck, > > Here is my solution but it doesn't do any graffing. > I think it is mathematically correct but it could be wrong. > I just wrote it real quick. It prints up something that > looks right to me. > > }}} <eucode> > include get.e > > function sum( sequence s ) > atom a > a = 0 > for i = 1 to length( s ) do > a+= s[i] > end for > return a > end function > > constant NumOfDice = 3 > constant NumOfSides = 6 > > constant MaximumRoll = NumOfDice * NumOfSides > > sequence chances, dice > chances = repeat( 0, MaximumRoll ) > dice = repeat( 1, NumOfDice ) > > integer roll Local variable roll is not used. > for d = 1 to power( NumOfSides, NumOfDice ) do > chances[sum(dice)] += 1 > dice[1]+=1 > for i = 1 to NumOfDice -1 do > if dice[i] > NumOfSides then > dice[i] = 1 > dice[i+1] += 1 -- this makes it faster: else exit > end if > end for > end for > > > printf( 1, "The distobution of %d %d sided dice rolls:\n", > {NumOfDice,NumOfSides} ) > puts( 1, "Value\tChance\n" ) > for i = 1 to length( chances ) do > printf(1, "%d\t%d\n", i&chances[i] ) > end for > if wait_key() then end if > </eucode> {{{ Regards, Juergen