MathGroup Archive 1998

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

Search the Archive

Re: A Monte Carlo Simulation with loop structure



In response to Daniel Sanders, I wrote:

>> a 9 seemed to come up less often a 10 supposedly in the experience of
>> gamblers.

>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}}

Reading the question properly shows that I have not answered the
question.  One method (using an exhaustive search via pattern-matching)
to compute the number of ways that sums of 9 and 10 can arise is as
follows:

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

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

Hence there are two more ways that sum to 10 (because summing to 9
includes the triple {3,3,3}).  

An exhaustive search can be avoided as follows: e.g., use Table to
construct all ways with sum 9:

	Table[{i,j,9-i-j},{i,6},{j,Max[1,9-i-6],Min[6,9-i-1]}]

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: Evaluate In Place
  • Next by Date: Re: A Monte Carlo Simulation with loop structure
  • Prev by thread: A Monte Carlo Simulation with loop structure
  • Next by thread: Re: A Monte Carlo Simulation with loop structure