Mathematica Pearls:
Problems and Solutions

Edited by Don 
Piele                                                                                Volume 5, No.1

Starting a new volume allows one to change some old ways and try new ideas. One field that I find particularly well suited to Mathematica is probability.  Recently, I have been working on notebooks for teaching probability at the introductory college level. I'd like to begin this volume with a deceptively simple problem made popular by Monty Hall.

Monty Hall Problem (Source---Marilyn vos Savant, Parade Magazine, Sept  9, 1990)

Monty Hall was the host of the daytime T.V. show "Let's Make A Deal" that  ran from 1963 to 1990.  One of games he made popular was to have a contestant  pick a curtain out of three possible curtains shown on stage. Behind one of  the curtains was a new car, but behind the other two was a booby prize---for example a cow. 

If you are allowed to only pick one door, your chances of winning the car are clearly 1/3. So to make it a bit more interesting, Monty Hall would tempt the contestant in the following way. Let's say they pick curtain number 1. Before the curtain was opened, he would reveal what was behind one of the curtains not picked---of course a curtain with a cow behind it,  never the car. Let's say he shows off the cow behind curtain number 3. Now Monty Hall would allow the contestant the option of changing their mind and switching from curtain number 1 to curtain number 2.

The question is: Are they better off switching curtains or staying put?

When this problem first appeared in Parade Magazine,  many readers, including mathematicians and statisticians, argured as follows: "When Monty Hall opened a door and showed you one of the cows, there are two unopened doors behind which one car and one cow are hidden. Therefore it does not matter if you change or not, since the chance of winning the car is 1/2 in both cases." 

What do you think?

Solution

Let's begin the anaylsis by simulating this game. First pick one of the curtains at random behind which to place the car. Do this with the random variable carCurtain.

carCurtain:=Random[Integer,{1,3}]

Check it out for 20 trials.

Table[carCurtain,{20}]

Looks OK. Now construct the prizes for a given contestant depending upon the curtain chosen.

Clear[prizes]
prizes[_]="Cow";
prizes[carCurtain]="Car";
Array[prizes,3]

This defines one game which we make into a game function.

Clear[game]
game[_]:= 
Module[{prizes,carCurtain},
	prizes[_]:="Cow";
	carCurtain:=Random[Integer,{1,3}];
	prizes[carCurtain]:="Car";
	Array[prizes,3]];

If we play the game 12 times we get the following random output:

experiment=Array[game, 12];
experiment //MatrixForm

Never Switch Stratgy

Assuming you do not switch curtains, let's compute the frequency of times 
you would have won had you picked curtain 1, 2, or  3. Simply replace 
each Car with a 1 and each Cow with a 0.

freqWithNoSwitch =
Apply[Plus,experiment /.{"Car"->1,"Cow"->0}]

This yields a relative frequency for winning with each curtain of:

relFreqWithNoSwitch = freqWithNoSwitch/12

The average is exactly what we expected: 1/3.

chanceWithNoSwithch =
Apply [Plus,relFreqWithNoSwitch]/3

Always Switch Strategy

What happens if we always switch? To understand the solution consider the following cases:
 1)  If the first pick is the curtain with the car behind it, then we will lose when we switch.
 2) However, if your first pick is a curtain with a cow behind it, we will always get the car if we switch. Why? Because Monty Hall will be forced to reveal the curtain with the other cow behind it, since he will never show the car.  Thus when we switch we must get the car -- it's all that is left. Thus we win if we first pick the Cow ( Cow->1 )  and lose if we first pick the Car (Car->0). So now our frequency becomes:

freqAlwaysSwitch =
Apply[Plus,experiment /. {"Car"->0,"Cow"->1}]

That's higher. And the relative frequency with a switch strategy is:

relFreqAlwaysSwitch =
freqAlwaysSwitch/12

The average gives the exact probability of 2/3.

chanceAlwaysSwithch =
Apply [Plus,relFreqAlwaysSwitch]/3

By following the strategy of always switching, you have doubled your chances of winning the car. Not bad! This was the answer Marilyn vos Savant gave.

Her readers, however, didn't agree.  Ms. vos Savant estimates she has received 10,000  letters, the great majority gloating over her apparent mistake. The most vehement criticism came from mathematicians and scientists with PhDs, who lamented the nation's innumeracy.

Your Turn

What happens when we extend this problem to include  N curtains, behind which we have placed P prizes (cars) and N-P cows (one behind each curtain), and we repeat the game R times? Create a function called montyHall[N,P,R] which will simulate the game R times and compare the chances of winning a prize by following the two strategies used above: 1) never switch; or  2) always switch. We assume of course that all curtains are equally likely to hide a prize and equally likely to be chosen. First get the function working for P=1 and then expand it to the general case.

montyHall[4,1,10]