People keep explaining the Monty Hall problem wrong
Someone once explained the Monty Hall problem to me:
A car is placed at random behind one of three doors. The other two doors have goats behind them. You pick a door without opening it. The host opens another door, shows you a goat, then asks: “Do you want to keep your door, or switch to the other unopened door?”
I thought for a while, then said, “It doesn’t matter.”
They rather smugly told me I was wrong: switching gives you a 2/3 chance of winning the car.
Eventually, we agreed to settle the question by writing a Python simulator. We each wrote one. Except my simulator said switching won 50% of the time, while theirs said it won 66% of the time.
How had we both taken the same problem, coded it up, and got different answers?
My simulator
In my code, I performed the following steps:
- I placed the car behind a door at random.
- I picked a door at random.
- The host opened one of the other two doors, also at random.
import random
random.seed(0)
doors = [0, 1, 2]
stay_wins = 0
switch_wins = 0
for turn in range(1_000_000):
car_door = random.choice(doors)
my_door = random.choice(doors)
# Open either of the other doors at random.
other_doors = [door for door in doors if door != my_door]
opened_door = random.choice(other_doors)
if opened_door == car_door:
# The host revealed the car, so the game ends.
continue
if my_door == car_door:
stay_wins += 1
else:
switch_wins += 1
finished_games = stay_wins + switch_wins
print("Stay: ", stay_wins / finished_games)
print("Switch:", switch_wins / finished_games)This prints:
Stay: 0.5007260965708439
Switch: 0.49927390342915606
In all the worlds where the host revealed the car, I assumed the host said, “Oh well, looks like you lost! Good night, everyone!”
In the worlds where the host did show a goat, I could now either stay with my door or switch to the other unopened door. In this version of the game, it didn’t matter which I did. Among the games which reached this decision, 50% had the car behind my door and 50% had it behind the other unopened door.
My friend’s simulator
Now we come to the important part, which people often aren’t careful about when explaining the problem (my friend wasn’t!). Their simulator worked like this:
- They placed the car behind a door at random.
- They picked a door at random.
- The host, knowing where the car was, intentionally opened a door which had a goat behind it.
import random
random.seed(0)
doors = [0, 1, 2]
stay_wins = 0
switch_wins = 0
for turn in range(1_000_000):
car_door = random.choice(doors)
my_door = random.choice(doors)
# Deliberately choose a door which does not contain the car.
possible_doors = [door for door in doors
if door != my_door and door != car_door]
opened_door = random.choice(possible_doors)
if my_door == car_door:
stay_wins += 1
else:
switch_wins += 1
finished_games = stay_wins + switch_wins
print("Stay: ", stay_wins / finished_games)
print("Switch:", switch_wins / finished_games)This time, it prints:
Stay: 0.333773
Switch: 0.666227
The host never revealed the car. In this version of the game, switching really did win 2/3 of the time.
There are many ways to explain this, but my preferred one leans on the host’s intentional choice. Suppose that, before opening a door, the host had asked, “Do you want your door, or both of the other two doors?” Obviously you would choose both other doors: together, they have a 2/3 chance of hiding the car.
The host then deliberately opens one of those two doors, having chosen one which doesn’t contain the car. This doesn’t change whether the car was in that pair of doors. The host is just messing around and showing you which of the two cannot win. Switching still wins exactly when the car was somewhere in the original pair.
In conclusion
When defining puzzles, it is important to be very clear about the rules. It is often tempting to be a little vague around exactly the part where the trick lies, because spelling it out might give the answer away. Except, that temptation can leave you with a different puzzle which has a different answer.
I don’t have a deep observation here. Just, maybe, be careful!