MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: A Monte Carlo Simulation with loop structure


  • To: mathgroup@smc.vnet.net
  • Subject: [mg11999] Re: A Monte Carlo Simulation with loop structure
  • From: Paul Abbott <paul@physics.uwa.edu.au>
  • Date: Fri, 17 Apr 1998 03:40:35 -0400
  • Organization: University of Western Australia
  • References: <6gr6oo$8n4@smc.vnet.net>

Daniel Sanders wrote:

> I owe the problem to J. Laurie Snell from his book, "Introduction to
> Probability".
>      In the early 1600s, Galileo was asked to explain the fact that,
> although the number of triples of integers from 1 to 6 with sum 9 is
> the same as the number of such triples with sum 10, when three dice are
> rolled,

One way to check this is to use ReplaceList:

  In[1]:= ReplaceList[Range[6], {___, a_, ___, b_, ___, c_, ___} :> 
	{a, b, c} /; a + b + c == 9]

  Out[1]= {{2, 3, 4}, {1, 3, 5}, {1, 2, 6}}

  In[2]:= ReplaceList[Range[6], {___, a_, ___, b_, ___, c_, ___} :> 
	{a, b, c} /; a + b + c == 10]

  Out[2]= {{2, 3, 5}, {1, 4, 5}, {1, 3, 6}}

> a 9 seemed to come up less often a 10 supposedly in the experience of
> gamblers.
>      Can you suggest native Mathematica code not emulating a procedural
> language for a Monte Carlo simulation experiment that runs many times
> keeping track of the proportions of 9s and 10s?  Thanks in advance,
> I'm interested in the looping mechanism.

We roll three dice, with each die as

  In[3]:= die := Random[Integer, {1, 6}]

10000 times as follows:

  In[4]:= Apply[Plus, Table[die, {10000}, {3}], 1]; 

and then count the 9s and 10s:

  In[5]:= {Count[%, 9], Count[%, 10]}

  Out[5]= {1181, 1288}

We can use Table to do looping:

  In[6]:= Table[With[{rolls=Apply[Plus, Table[die, {10000}, {3}], 1]},
	{Count[rolls, 9], Count[rolls, 10]}],{10}]

  Out[6]= {{1120, 1242}, {1176, 1194}, {1134, 1259}, {1155, 1306},  
	{1135, 1297}, {1110, 1256}, {1224, 1215}, {1171, 1248},  
	{1129, 1245}, {1155, 1277}}

Cheers,
	Paul 

____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia            Nedlands WA  6907       
mailto:paul@physics.uwa.edu.au  AUSTRALIA                            
http://www.pd.uwa.edu.au/~paul

            God IS a weakly left-handed dice player
____________________________________________________________________



  • Prev by Date: Re: calculation
  • Next by Date: Re: LinearProgramming question (speed problem)
  • Prev by thread: Re: A Monte Carlo Simulation with loop structure
  • Next by thread: RE: A Monte Carlo Simulation with loop structure