Re: Gaussian Distribution Using Dice

new topic     » goto parent     » topic index » view thread      » older message » newer message

Juergen Luethje wrote:
> 
> 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.
> >
> <font color="#330033">> </font>
> <font color="#330033">> </font><font color="#0000FF">include </font><font
> color="#330033">get.e</font>
> <font color="#330033">></font>
> <font color="#330033">> </font><font color="#0000FF">function </font><font
> color="#330033">sum( </font><font color="#FF00FF">sequence </font><font
> color="#330033">s )</font>
> <font color="#330033">> 	</font><font color="#FF00FF">atom </font><font
> color="#330033">a</font>
> <font color="#330033">> 	a = 0</font>
> <font color="#330033">> 	</font><font color="#0000FF">for </font><font
> color="#330033">i = 1 </font><font color="#0000FF">to </font><font
> color="#FF00FF">length</font><font color="#330033">( s ) </font><font
> color="#0000FF">do</font>
> <font color="#330033">> 		a+= s[i]</font>
> <font color="#330033">> 	</font><font color="#0000FF">end for</font>
> <font color="#330033">> 	</font><font color="#0000FF">return </font><font
> color="#330033">a</font>
> <font color="#330033">> </font><font color="#0000FF">end function</font>
> <font color="#330033">></font>
> <font color="#330033">> </font><font color="#0000FF">constant </font><font
> color="#330033">NumOfDice = 3</font>
> <font color="#330033">> </font><font color="#0000FF">constant </font><font
> color="#330033">NumOfSides = 6</font>
> <font color="#330033">></font>
> <font color="#330033">> </font><font color="#0000FF">constant </font><font
> color="#330033">MaximumRoll = NumOfDice * NumOfSides</font>
> <font color="#330033">></font>
> <font color="#330033">> </font><font color="#FF00FF">sequence </font><font
> color="#330033">chances, dice</font>
> <font color="#330033">> chances = </font><font
> color="#FF00FF">repeat</font><font color="#330033">( 0, MaximumRoll )</font>
> <font color="#330033">> dice = </font><font color="#FF00FF">repeat</font><font
> color="#330033">( 1, NumOfDice )</font>
> <font color="#330033">></font>
> <font color="#330033">> </font><font color="#FF00FF">integer </font><font
> color="#330033">roll</font>
> <font color="#330033"></font>
> <font color="#330033">Local variable roll is </font><font color="#0000FF">not
> </font><font color="#330033">used.</font>
> <font color="#330033"></font>
> <font color="#330033">> </font><font color="#0000FF">for </font><font
> color="#330033">d = 1 </font><font color="#0000FF">to </font><font
> color="#FF00FF">power</font><font color="#330033">( NumOfSides, NumOfDice )
> </font><font color="#0000FF">do</font>
> <font color="#330033">> 	chances[sum</font><font color="#993333">(</font><font
> color="#330033">dice</font><font color="#993333">)</font><font color="#330033">]
> += 1</font>
> <font color="#330033">> 	dice[1]+=1</font>
> <font color="#330033">> 	</font><font color="#0000FF">for </font><font
> color="#330033">i = 1 </font><font color="#0000FF">to </font><font
> color="#330033">NumOfDice -1 </font><font color="#0000FF">do</font>
> <font color="#330033">> 		</font><font color="#0000FF">if </font><font
> color="#330033">dice[i] > NumOfSides </font><font color="#0000FF">then</font>
> <font color="#330033">> 			dice[i] = 1</font>
> <font color="#330033">> 			dice[i+1] += 1</font>
> <font color="#330033"></font>
> <font color="#FF0055">                -- this makes it faster:</font>
> <font color="#0000FF">                else</font>
> <font color="#0000FF">                        exit</font>
> <font color="#330033"></font>
> <font color="#330033">> 		</font><font color="#0000FF">end if</font>
> <font color="#330033">> 	</font><font color="#0000FF">end for</font>
> <font color="#330033">> </font><font color="#0000FF">end for</font>
> <font color="#330033">></font>
> <font color="#330033">></font>
> <font color="#330033">> </font><font color="#FF00FF">printf</font><font
> color="#330033">( 1, </font><font color="#00A033">"The distobution of %d %d sided
> dice rolls:\n"</font><font color="#330033">, </font><font
> color="#993333">{</font><font color="#330033">NumOfDice,NumOfSides</font><font
> color="#993333">} </font><font color="#330033">)</font>
> <font color="#330033">> </font><font color="#FF00FF">puts</font><font
> color="#330033">( 1, </font><font color="#00A033">"Value\tChance\n" </font><font
> color="#330033">)</font>
> <font color="#330033">> </font><font color="#0000FF">for </font><font
> color="#330033">i = 1 </font><font color="#0000FF">to </font><font
> color="#FF00FF">length</font><font color="#330033">( chances ) </font><font
> color="#0000FF">do</font>
> <font color="#330033">> 	</font><font color="#FF00FF">printf</font><font
> color="#330033">(1, </font><font color="#00A033">"%d\t%d\n"</font><font
> color="#330033">, i&chances</font><font color="#993333">[</font><font
> color="#330033">i</font><font color="#993333">] </font><font
> color="#330033">)</font>
> <font color="#330033">> </font><font color="#0000FF">end for</font>
> <font color="#330033">> </font><font color="#0000FF">if </font><font
> color="#330033">wait_key() </font><font color="#0000FF">then end if</font>
> <font color="#330033">> </font>
> 
> Regards,
>    Juergen
> 
> 

Oh yeah, that roll integer don't need to be there.
I started to use it then decided I needed the dice sequence instead.
Thanks for speeding it up with that exit statement.
I forget about stuff like that sometimes.

Below lies the signature of Lewis Townsend
Lewy T

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu