# What 1000 PhDs got wrong

I’m sure that many of you have heard of the famed Monty Hall problem. It was loosely based on the game show *Lets Make A Deal* and it’s original host Monty Hall. It was posed to Marylin vos Savant in her “Ask Marylin” column in 1990, and has been a favorite brain teaser ever since. The question is as follows “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 №1, and the host, who knows what’s behind the doors, opens another door, say №3, which has a goat. He then says to you, “Do you want to pick door №2?” Is it to your advantage to switch your choice?” . Vos Savant responded that a contestant should alway switch, as contestants who switch have a 2/3 chance of winning the car, while contestants who stay only have 1/3 chance of winning. I’m not going to get into the actual math here but a great explanation can be found on this video here.

The response was overwhelming disbelief, nearly 10,000 readers wrote in that she was wrong. A group of nearly 1000 PhDs, many of them mathematicians wrote in as well, with one PhD’s solid logic being “If all those other PhDs are wrong we would all be in serious trouble”. Marylin however was correct, which shouldn’t come as such a shock considering her 228 IQ. Today I’m going to walk you through a Python function that I wrote that simulates the Monty Hall game show, and we shall see what we get.

def lets_make_a_deal(door_letter,stay_or_switch,num_of_games,details,prob_list=[.33,.33,.33]):

##The function takes five inputs the 1st is the door letter of your #choice, the second is your decision whether or not to stay with #your door, the third is the number of games you wish to play, the #fourth is whether or not you want the game to speak out the details #or not (True or False) , I would suggest turning this off if you're #playing more than a few games.

#LETS PLAY

win_count=0

loss_count=0

import numpy as np

import random

##Forcing the sum of the probabilities to one

new_probs = []

new_probs.append(prob_list[0]/sum(prob_list))

new_probs.append(prob_list[1]/sum(prob_list))

new_probs.append(prob_list[2]/sum(prob_list))

for i in range(num_of_games):

doors=['a','b','c']

##Computer is randomly selecting a door from the above list that #contains the car

car = np.random.choice(doors,p=new_probs)

if details is True:

print('Prize is behind door {}'.format(car))

choice=door_letter

if details is True:

print('Contestant chose door {}'.format(choice))

##Choosing a door that isn't the car and the door that you chose, #for the host to open

door_to_remove=np.random.choice(list(set(doors) - set(choice) - set(car)))

doors.remove(door_to_remove)

doors.remove(choice)

if details is True:

print('Host opened door {} '.format(door_to_remove) + 'and it contains a goat :(')

print('These doors remained available: {}'.format(doors))

##If you decided to switch your choice is updated to the one door that remains in the door list.

if stay_or_switch=='switch':

if details is True:

print ('Contestant switched doors to door{}'.format(doors))

new_choice=doors[0]

## If you decided to stay your choice remains the same.

else:

new_choice=choice

if details is True:

print ('Contestant stays with original door')

##Defining a win as when your new choice is the same door that #contains the car

won = new_choice==car

if won is True:

if details is True:

print "you won"

win_count += 1

else:

if details is True:

print "sorry you lost"

loss_count += 1

print "win count " + str(win_count)

print "loss count " + str(loss_count)

O.K. now that I walked you through the code, lets see if our function agrees with Marylin or not.

Well we don’t really get any sort of idea with just one game let’s crank it up a bit.

As you can see when we played ten thousand games if we switched we won about 6700 times, however when we stayed we won around 3400 times. Looks like Marylin got this one right.