Simulating the Monty Hall Problem

2025-05-04

The Monty Hall Problem is a famous probability puzzle based on a game show scenario. In this problem, a contestant is presented with three doors. Behind one door is a car (the prize), and behind the other two doors are goats. After the contestant makes their initial choice, the host, who knows what is behind each door, opens one of the other two doors, always revealing a goat. The contestant is then given the option to stick with their original choice or switch to the remaining closed door.

A straightforward explanation of the probabilities involved is as follows: the chance of winning the car by not switching is 1/3. This is because there are three doors, and only one has the car. Conversely, there is a 2/3 chance that the contestant initially picked a goat. When the host reveals a goat behind one of the other doors, switching doors gives the contestant a 2/3 probability of winning the car. Thus, it is advantageous to switch.

You can simulate the Monty Hall problem with a simple program. The program randomly selects one of the three doors to hide the car. The contestant's initial choice is also made randomly among the three doors. When the contestant decides to stick with their original choice, the probability of winning the car remains 1/3, regardless of which door the host opens to reveal a goat. Therefore, there's no need for the simulation to select a door to open in this case.

However, if the contestant opts to switch, the program will reveal one of the other doors that conceals a goat. To determine which door to open, the program randomly selects a door from the remaining options until it finds one that is neither the contestant's chosen door nor the door hiding the car. In this scenario, the probability of winning the car increases to 2/3. This simulation effectively illustrates the counterintuitive nature of the probabilities involved.