Problem Description
It’s a quite well-known and long-running TV show in the US called “Let’s make a deal”. It was initially hosted by Mounty Hall, hence the name. In austria we often refer to it as the “Ziegenproblem” or, translated, the “goat problem”. I actually prefer that name, I think.
Problem states as follows: We have three doors. We know that behind two of the doors there is a goat1 while the remaining door covers a car. If you open the door to the car then you win (the car), otherwise you go home empty handed.
You now pick one door of your choice. After you publish your choice, the game master (Mr. Hall) opens another door which covers a goat. You now have the choice to keep the previously chosen door or switch to the other not yet opened door.
I would like to examine if and why you should change your choice.
Legal notice
It is important to note that we are working with probability here. This means that for one specific case, we can give recommendations what you could do but we cannot guarantee anything. Roulette is the most prominent example: I can tell you that if a red number was drawn seven times in a row then I would recommend you to set your money on Black now. It may still be the case that another red number will be drawn in the next round and this is not my fault.
The same concept applies here: I am going to recommend you to switch the doors2. It is still possible that the car will be behind the door you chose previously - I am not able to and also do not want to guarantee anything.
Coding
Let’s start with the fun part: Code the problem and test what happens.
Step 1: No change
This is the easy case: You ignore the opened door from the game master and stick to the previously defined door. The code to that is easy as well:
import random
hits = 0
rounds = 1_000
for _ in range(rounds):
car_choice = random.randint(0, 2)
your_choice = random.randint(0, 2)
# game master chooses the other door
choices = {0, 1, 2}
# the game master will not choose the car door
choices.discard(car_choice)
# the game master will not choose your door
choices.discard(your_choice)
master_choice = random.choice(list(choices))
# You may now switch doors, but in this case, you don't
if car_choice == your_choice:
hits += 1
print(hits / rounds)
# output: something around 0.33
Note that random.randint(0, 2)
randomly chooses $0, 1$ or $2$ where each interger has the same probability. This is important for our case. Also, the higher you choose rounds
, the closer to 0.33
the output value will be (most probably).
So it is easy to see: If you do not change the door, you have a $1/3$ chance to win the car.
Step 2: You change
We essentially do the same again, but this time you switch the door.
import random
hits = 0
rounds = 1_000
for _ in range(rounds):
car_choice = random.randint(0, 2)
your_choice = random.randint(0, 2)
# game master chooses the other door
choices = {0, 1, 2}
# the game master will not choose the car door
choices.discard(car_choice)
# the game master will not choose your door
choices.discard(your_choice)
master_choice = random.choice(list(choices))
# You may now switch doors, but in this case, you don't
your_new_choices = {0, 1, 2}
# Drop the two other doors
your_new_choices.discard(your_choice)
your_new_choices.discard(master_choice)
# Define your new choice
new_choice = your_new_choices.pop()
if car_choice == new_choice:
hits += 1
print(hits / rounds)
# output: something around 0.66
So we see that changing the door gives you $0.66$ or $66$% probability of winning.
Step 3: You change, simplified
Now there is another approach of defining this second part which lets us get to the correct conclusion even faster.
Assume you chose a door and the game master chose a door and then there is only one door left. We know that the game master’s door is not the car door, by definition of the game. Hence the car door is either yours or3 the one you will now switch to. In particular, you will win the game if and only if you previously chose a goat door. See where this is headed?
No? Let me tell you: Assuming you want to win, then for your first choice, you have two possible doors you may pick (namely, one with a goat). For your second choice, you do not have a choice at all - your second door is already fixed. That is by the way the reason that I just used new_choice = your_new_choices.pop()
above: Because there is only one element left in the set. In step 1 (where you did not change) I did not use pop random.choice(...)
. Why? Because you may have chosen the correct door and then the game master has two possibilities to choose from.
The code also gets easier this time:
import random
hits = 0
rounds = 1_000
for _ in range(rounds):
car_choice = random.randint(0, 2)
your_choice = random.randint(0, 2)
if your_choice != car_choice:
hits += 1
print(hits / rounds)
# outputs ~0.66
Nice, right?
Mathematics
The fun part is over now, let’s get serious. Or stop reading here if you are not in the mood for some boring maths.
No, don’t worry. It won’t be too mathematical. Mostly, everything is said - I am just happy that I can write down mathematical notation in my blog and have to use that now…
Step 1: No change
Let’s again consider the easier case first: You choose your door and stick to it, no matter what the game master tells you. The audience may also shout you down to switch the doors but you stand firm with your choice.
The result is: You had your hit. You had a $1/3$ chance of choosing the correct door and this one will not change as soon as you do not change.
Step 2: You change
I actually already explained that earlier: Arguing the correct way, you win if and only if you choose a goat in your first choice. The second choice is not a choice any more. You have a $2/3$ or $66$% chance to get a goat.
Conditional probability?
Everybody who knows about mathematics knows the concept of conditional probability. There was some confusing formula we used for that and actually nobody really understood what we were doing at that time…
Now we cannot use conditional probability here because this would require us to have two independent events. Independence is difficult because your choice is dependent on the choice of the first door and two is difficult because as discussed before your second choice is not a choice any more. So where to get your second event from?
I actually thought really hard about modelling that in some way so that we could use conditional probability but this either got out of hand quickly (modelling where the car is, which door you chose, which door the game master chose and if you switched) or it was a dead end. Sorry…
Conclusion
Switch the doors. Also, again, I cannot guarantee your win. I can just increase your odds. This is what probability does.