You’ve all heard this puzzle. Remember the game show “Let’s Make a Deal”, there are three closed doors and behind one is a prize. The contestant picks a door, then the host – Monty Hall – opens a different door. The prize is not behind the door Monty opens. Now the contestant has an option to stick to the original choice or switch. Should you switch or not?
Turns out the answer is that you should always switch. In fact the probability of winning the prize is 2/3 if you switch.
Many people have hard time understanding why this is so. Once I explained the solution to a friend and he still did not believe me. So I wrote the following program to simulate 10,000 games and calculate the probability. Here is the code in Python:
from random import randintdef pick (doors):result = randint (1,3)while result in doors:result = randint (1,3)return resulttotal_wins = 0for i in range (1,10000):prize_door = randint (1,3)guess_door = randint (1,3)monty_door = pick ([prize_door, guess_door])switched_door = pick ([guess_door, monty_door])if (switched_door == prize_door):total_wins += 1print “Total games: %d Total wins: % d ” % (i, total_wins)
Total games: 9999 Total wins: 6700Total games: 9999 Total wins: 6675Total games: 9999 Total wins: 6619