Ever since I read about Monty Hall problem in “The Drunkard’s Walk: How Randomness Rules Our Lives” book by Leonard MlodinowÂ from of the California Institute of Technology, I always wanted to try and run a simulation to see that the math is correct.

It is one of those problems, where the first answer that comes to mind is usually wrong, and the correct answer to the problem is counterintuitive, but it clearly comes through after doing the math or running the code.

As Wikipedia describes the problem, quoting a letter by Steve Selvin to the American Statistician in 1975:

â€œ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?â€

I won’t go on explaining the mathematical solution here – there are plenty of those on the internet using either intuitive solution/tree diagram or conditional probability/Bayes theorem.

However here’s the code to run the simulation. The output is as expected – switching the door does indeed increase the winning probability.

Hold strategy wins: 3287, win probability: 0.33 Switch strategy wins: 6713, win probability: 0.67

There are built in algorithms in gaming that analyze your choices, so how can anyone use an online gaming model to prove randomness? Switching doors doesn’t improve chances of winning. How many times has someone watched tv game shows where peeps change their mind and get a lesser prize than their original choice.