Python code to simulate the Monty Hall Problem (MHP) and verify winning probabilities
Command: python3 MHP.py NUMBER OF SIMULATIONS
Recommended NUMBER OF SIMULATIONS
: 2500-3000 (although the more the merrier)
Approximate run-time for 2500-3000 simulations: 1 minute
- Probability of winning if you switch = 2/3
- Probability of winning if you stick = 1/3
Assume (#winning ratio after switching) as a Bernoulli random variable with p = 2/3 (Expectation = 2/3)
or,(#winning ratio after sticking) as a Bernoulli random variable with p = 1/3 (Expectation = 1/3)
The results we get are in accordance with the Law of Large Numbers
i.e with very high number of simulations, the winning ratio does converge to its expected value
About the problem: https://en.wikipedia.org/wiki/Monty_Hall_problem
MIT Maths for CS: https://www.youtube.com/watch?v=SmFwFdESMHI