Simulating the Monty Hall Paradox With Javascript
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
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
- Stay with our original guess
- 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
- Elements of Programming
- Beginning Math and Physics for Game Programmers
- From Mathematics to Generic Programming
- Data-oriented design: software engineering for limited resources and short schedules
- Design of Design, The: Essays from a Computer Scientist
- Mythical Man-Month, The: Essays on Software Engineering, Anniversary Edition
- More Effective C++: 35 New Ways to Improve Your Programs and Designs
- Mathematics for Machine Learning
- The Pragmatic Programmer: Your Journey To Mastery, 20th Anniversary Edition (2nd Edition)
- Schaum's Outline of Essential Computer Mathematics 1st Edition
- All recommended resources