There is a popular online puzzle called the Monty Hall Problem. This puzzle dates to a letter by Steve Selvin published in the journal American Statistician in 1975. Similar statistical problems had been published by Martin Gardner in Scientific American, but this particular one is relatively simple to state and leads to a somewhat paradoxical result. It was republished in Parade magazine in 1990 in a regular column by Marilyn vos Savant where it received wider attention.
Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what’s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, “Do you want to pick door No. 2?” Is it to your advantage to switch your choice?
The paradox stems from the idea that the player has a final choice of two doors, with no direct knowledge of the car location, so it should not matter if he switches or not. But with the typical assumptions of the game show situation, the odds are actually doubled (from 1/3 to 2/3) if the player switches doors. However, those probabilities depend on those underlying assumptions, and it can be surprising which assumptions affect the odds. This code explores several of those options by doing statistical simulations.
montyhall.f90 (11.1 KB)
Here is a typical output:
$ gfortran montyhall.f90 && a.out
sim1: N= 1000000 win: 667274 0.667 loss: 332726 0.333
sim2: N= 1000000 win: 666840 0.667 loss: 333160 0.333
sim3: N= 1000000 win: 666319 0.666 loss: 333681 0.334
sim4: N= 1000000 win: 332696 0.333 loss: 333614 0.334
sim5: N= 1000000 win: 666334 0.666 loss: 333666 0.334
sim6: N= 1000000 win: 666575 0.667 loss: 333425 0.333
sim7: N= 1000000 win: 0 0.00 loss: 334181 0.334
I should mention that internally the doors are numbered 0, 1, and 2 in this code. This simplifies some of the math, but does not change the puzzle in any significant way.
The sim1 subroutine uses what I think are the typical implicit assumptions. Namely that the car door is chosen randomly, the player choice is random, Monty Hall is required to expose a goat regardless of the player choice, and that there is no movement of the car and goats behind the doors after either of the choices have been made. This simulation shows the expected behavior that the chance of winning the car is doubled if the player switches doors.
The sim2 and sim3 subroutines show the results if the specific goat door that is exposed is not random. It is sometimes argued that this affects the odds. This simulation shows that is not the case. The sim2 subroutine shows the results if the player knows the goat door algorithm and attempts to use it to advantage. The sim3 subroutine shows what happens if the goat door uses the same algorithm (the largest goat door is always exposed), but the player does not know the algorithm and chooses the final door in the usual way. The results of this simulation surprised me a little. Especially in the sim2 case, I would have thought that the player could have used that information to gain a little more advantage.
The sim4 case also surprised me a little. In this simulation Monty Hall picks an unchosen door at random rather than always exposing a goat door. My intuition told me that it should not matter, with knowledge or random chance, as long as a goat was exposed, I thought the initial choice always had 1/3 chance of winning and switching would then always have a 2/3 chance of winning. After seeing the results (1/3 and 1/3), I then realized what happens. Those increased odds of switching are because the car can initially be behind the unselected doors twice as often as the selected door. That part of my intuition was correct. But what I missed is that when Monty Hall exposes the car and ends the game, that eliminates exactly the advantage of switching. So for this case, the player’s initial choice is correct 1/3 of the time, the game ends early 1/3 of the time, and the remaining door is correct 1/3 of the time. So for the final choice, it doesn’t matter if the player switches or not in this case.
The sim5 and sim6 cases did not surprise me, I just included these cases to convince myself that my intuition was correct in these two situations (after all, I was wrong about the sim4 case). One case is when the car door is random but the player always initially chooses door 1, and the other is that the car is always door 1 but the player, who does not know that, always chooses randomly. It does not matter which door is predetermined in these simulations.
The sim7 case shows what happens if Monty Hall is not required to give the player a second choice. In this simulation he only gives the player a second opportunity to switch when he has chosen the car door initially. In this case, the player should never switch (and he would win 1/3 of the time), but if he makes the usual implicit assumptions and always switches, then he will lose every time. This did not surprise me, but it does show how important those implicit assumptions are to the game strategy. The optimal strategy against a possibly malicious Monty Hall would be to flip a coin for the final choice; that would result in early game termination up to 2/3 of the time, a win 1/6 of the time, and a loss 1/6 of the time.
There is also some psychology that comes into play. Many people would feel worse about initially choosing the correct door and then switching at the end than they would about choosing initially the wrong door and then not switching given the opportunity. (This is related to the Trolley Problem, a well known moral dilemma, where many people feel less guilt taking no action rather than taking an active role in the outcome.) Feelings of loyalty, or commitment, to the initial choice also come into play, even though, in this case, the chance of winning doubles by switching (with the usual implicit assumptions). Some people also think of Monty Hall as a malicious adversary in the game, giving the player choices designed to entice him to choose a goat (as in the sim7 model above).
There may be some other implicit assumptions and other game strategies that are not explored in this code. If you recognize a new case, then please add that to the code and show the results here. It is interesting to see both cases, where a strategy is expected to change the odds but doesn’t, and cases where a strategy is not expected to change the odds but does.