Re: Interesting Simulation Problems....(3)
- To: mathgroup@smc.vnet.net
- Subject: [mg12276] Re: [mg12084] Interesting Simulation Problems....(3)
- From: "Tomas Garza" <tgarza@mail.internet.com.mx>
- Date: Tue, 5 May 1998 03:30:13 -0400
LinLi wrote: > the following are some interesting simulation problems. Just > wonder how i can do it with mathematica .... >3. Aces Probelm (Warren Weaver got this wrong in the first edition of >his book on probability) > There are four players. A bridge hand is dealt and you state to the >other three players that > you have an ace. Find the probability, as calculated by someone >else, whether or not you > also have another ace. Later, you annouce that you have the Ace of >Spades. What now is > the probability that you have another ace? (also by simulation) LinLi: The add-on DiscreteMath`Combinatorica` affords an easy way to sample without replacement. In[1]:ÿ<DiscreteMath`Combinatorica` First, define your maze of cards using Distribute, so that each card is an ordered pair {C, n}, i.e. a colour and a number: In{2}:üolors ÿA,C,S,H}; numsÿa, 2, 3, 4, 5 ,6, 7, 8, 9,1 0, j, q, k}; In[3]:ÿ[a_, b_]:ÿa, b}; cardsÿstribute[f[colors,nums],List] ; A sample without replacement of 13 cards from your maze is obtained using RandomKSubset: In[4]:ÿt ÿandomKSubset[cards,13] Out[4]{{A,a},{A,2},{A,3},{A,j},{A,k},{C,2},{C,5},{C,k},{S,5},{S,6},{S,7},{S,j}, {H, 2}} and Cases [tt, {_, a}] will tell which of the 13 cards are aces: In[5]:üases[tt,{_,a}] Out[5]ÿ{A,a}} Now produce a sample of, say, 10,000 hands of 13 cards (perhaps 100,000 would perform better): sampleúble[RandomKSubset[cards,13],{10000}]; In[6]:subÊses[#,{_,a}]&/@sample; In[7]:atLeastOneAce ýeleteCases[sub,{}]; In[8]:ÿength[atLeastOneAce] Out[8]ö954 You then have a relative frequency of 6954/10000 of hands where there is at least one ace. The conditional probability thet there is another ace, given that there is at least one, can be estimated by counting how many of the hands in atLeastOneAce have more than one ace: In[9]:moreThanOneAceþlect[atLeastOneAce,Length[#]>1&]; Length[moreThanOneAce] Out[9]ò525 The required conditional probability is thus estimated by 2525/6954. Now, if you announce that you have the ace of spades {S, a} In[10]:aceOfSpadesÊses[atLeastOneAce,{___,{S,a},___}]; Length[aceOfSpades] Out[10]ò514 then there are the following number of hands in the sample where there is an additional ace: In[11]:Select[aceOfSpades,Length[#]>1&]; Length[%] Out[11]ñ371 Summarizing, a) the relative frequency of hands where there is more than one ace, given that there is at least one, is 2525/6954 ð.363 b) the relative frequency of hands where there is one more ace, given that you have the ace of spades is 1371/2514 0.545. Good luck, Tomas Garza Mexico City