DEV Community

enricodelarosa
enricodelarosa

Posted on • Updated on

Monty Hall didn't make sense so I made my own simulator

If you're not familiar with the Monty Hall problem, here's a short introduction.

Check this link out if you want to try playing the game first.

If you google the solution to the monty hall problem it will say that the best strategy is to switch every time. If you switch, there's a 66% chance that the car is behind the door you switch to. If you don't switch and stay on the door you chose, then you only have 33% chance of winning.

THIS DID NOT MAKE SENSE TO ME AT ALL. Why would switching give me a higher chance of winning? Is it irrelevant because I'm only playing one game? How can the answer be true?

You can try looking up the binomial distribution function for this but I didn't think that would convince me either. So I embarked on a quest to see the probabilities for myself. I started by making a monty hall game then I added a simulator that would play the game multiple times with the two strategies. I played each strategy 2,000 times and the graph said it all.

Switch vs Stay Graph

At first it seems irrelevant if you switch or not but the truth is that switching or staying has a significant impact on the outcome. This makes me wonder how often this phenomenon happens in real life where our choices are seemingly irrelevant but in fact have significant impact on the outcomes.

Building the game was pretty straightforward except for the fact that I had to make my own svg images for faster loading. Adding the simulator was also straightforward except that I had to slowdown the clicks in the loop so that they would be seen by the user otherwise, it would just do it really really fast without showing that the game was played.

Top comments (0)