Topics About Contact Resources Quotes

Simulating the Monty Hall Paradox With Javascript

The "Monty hall paradox" or "Monty hall problem" was made famous by a game show hosted by Monty Hall.

How It Works

We are presented 3 doors, behind 1 is a great prize, behind the other 2 doors are undesirable things. We guess 1 of the 3 doors at random.
We know that at least one of the remaining doors doesn't have the prize behind it.
Now, the host eliminates a door that doesn't have the prize, the host knows which door has the prize.

Here comes the tricky part, the hosts asks us if we want to stay with our original guess or switch to the other remaining door. Should we stay or switch? Does it matter?
Isn't it 50/50? It seems that we have a 1 in 2 chance to win if we stay or switch but it's not 50/50, it turns out we should switch.

If we are skeptical about that, and it does seem suspicious, we should test it.
Fortunately computers excel at doing repetitive tasks many times, so let's put ours to work.

Simulate the Monty Hall Problem 1,000,000 Times

Not switching doors we won of games.
Switching doors we won of games.

Why We Should Switch

At the start of the game we have a 1 in 3 chance of guessing the prize door, which means we have a 2 in 3 chance of guessing wrong.

What if at this point if the host gave us the following options

  1. Stay with our original guess
  2. Switch and win if the prize is behind either of the doors we didn't guess

The answer is clear to us, we should switch because that doubles our chances at winning.

This is why we should switch eliminating a door compresses the 2 in 3 chances of being correct in the remaining door, it still represents that block of 2 doors we did not guess. Switching allows us to take the 2 in 3 chances instead of the 1 in 3 chances.

We might say that this still sounds suspicious, especially since we already know that 1 of the 2 doors we don't choose will not have the prize, this may seem like some kind of trick or fudging the numbers, but we put it to the test and it checks out.

Resources