The Monty Hall problem was popularized as part of a television game show called "Let's Make a Deal" and named after its original host, Monty Hall.
In the show, there is a host and a player. There are 3 doors on the set. One has a car behind it and the other two have a goat each, behind them. Only the host knows where the car is and where the goats are.
The player was asked to guess behind which door the car was. Let's say he picked Door 1. That means that either Door 2 or Door 3 or both has a goat behind it.
The player was asked to guess behind which door the car was. Let's say he picked Door 1. That means that either Door 2 or Door 3 or both has a goat behind it.
The host, who knew what was behind each of the doors, opens one of the 2 doors not chosen, behind which he knew there was a goat. Let's say he opened Door 3.
So, there were 2 closed doors left; one with a goat and another with a car. The host gave the player the opportunity to stick to his original choice of Door 1 or switch to Door 2. What do you think the player should do - stick to their initial choice or should they switch?
It would be advantageous to the player to switch to the door which was not chosen nor opened, because as shown, it now has the combined probability of 2 doors.
Although there is no certainty that a switch is always advantageous, in the long run, it would be so.
This can be demonstrated through a Python script that simulates a 1000 trials of the Monty Hall problem.
It would be advantageous to the player to switch to the door which was not chosen nor opened, because as shown, it now has the combined probability of 2 doors.
Although there is no certainty that a switch is always advantageous, in the long run, it would be so.
This can be demonstrated through a Python script that simulates a 1000 trials of the Monty Hall problem.
from random import randint
wins, losses = 0, 0
print("In our 1000 simulations, we assume that the player always switches doors.")
print("Hence, if car and choice are the same, he loses by switching.")
print("In all other cases, he wins.\n")
input("Press any key to continue\n=========================")
print("Car Choice Wins Losses")
print("=== ====== ==== ======")
for i in range(1000):
list1 = list2 = [1, 2, 3]
car, choice = randint(1, 3), randint(1, 3)
print("%2d%5d" % (car, choice), end='')
if car == choice:
losses += 1
else:
wins += 1
print("%7d%7d" % (wins, losses))
print(" | |")
print(" v v")
print(" Wins Losses")
if wins > losses:
print("The wins is greater than the losses. Shows that switching is advantageous.")
else:
print("This turn of events was not expected.")
OUTPUT
: : ::: :::
: : ::: :::
: : ::: :::
: : ::: :::
1 1 668 330
3 3 668 331
3 1 669 331
| |
v v
Wins Losses
: : ::: :::
: : ::: :::
: : ::: :::
1 1 668 330
3 3 668 331
3 1 669 331
| |
v v
Wins Losses
The figures vary slightly from execution to execution. Output reveals that switching is advantageous over sticking to the original choice.