Imagine yourself in a large circular
room, totally empty, except for the presence of three doors. Just
three unremarkable doors, completely identical in size, shape and
colour. BUT WAIT. A note mysterious emerges from underneath the
middle most door. Retrieving the note you read:
We three doors of hope and misery,
Behind one of us, your wildest desires
will be,
But fail to choose the right one of
three,
And only sorrow and loss will beget
thee,
Your first thought upon reading the
note is how unfortunate you are to have walked into some Hobbit-like
riddling game. Mulling over the note once more, you reason that one
door probably leads to something good and the other two doors
probably lead to something bad. You surmise that the thing to do is
pick one of the doors in hopes that, even if it conceals something
bad, at least you'll be able to get out of the retched room.
You pick a door and just as you are
reaching for the doorknob, you hear a loud bang and one of the other
two doors bursts open, revealing a pile of sooty coal with a note
tacked to the top of it. After scrambling up the pile of coal to get
the second note you read:
Now two doors remain to choose from
you see,
The exclusion of one sorrow I have
granted for thee,
Stay or switch from your choice must
ye,
Now choose for us which one it will
be,
Do you stick with your original door
choice or switch? You are staring blankly from one door to the next
when suddenly an old statistics professor of yours materializes from
behind the pile of coal. Sooty and slightly disoriented-looking, he
walks towards you and exclaims “ There is a 2/3rd chance of winning
if you switch doors but only a 1/3rd chance of winning if you stick
with the original door!'
You think to yourself; Well that can't
be right! Shouldn't the probability now be fifty-fifty? If only I had
a . . .
'Pop', a computer with python 3
emerges into existence right in front of you. 'Ahah!' you exclaim,
'I can write a computer program that simulates the probability of
winning given that I switch!'
At least, that is what I did when I
encountered this problem, however less gloriously. This is informally
known as the Monty Hall Problem, thus named for the host of an old
game show which presents a similar scenario to its contestants.
There is a large body of theoretical
evidence supporting the fact that switching doors IS better. But even
after applying Conditional Probability, Bayes Theorem and the Law of
Total Probability, I still found myself struggling to believe it.
Being the CompStatNerd that I am, I decided to write out a program to
simulate the problem. I will post my code here only because it is
entirely of my own making and it is really quite simple.
I have set up the program to simulate
the case where the individual always switches doors. The program
tallies the number of total_wins
and total_losses that result
from the given number_of_games
played. The doors are represented as an ordered list containing two
goats and one car.
For each time that the game is played,
one of the 'doors' (containing either 'goat',
'goat' or 'car')
is chosen at random and removed from the list.
If the door chosen contained a car,
then exactly two goats remain in the list. If the door chosen
contained a goat, then exactly one car and one goat remain in the
list. If the former is true, then one of the two goats remaining is
chosen at random and is removed from the list. This list now contains
only one goat. If the latter is true, then the only goat in the list
is removed. This list now contains only one car.
A win is scored if the resulting list
contains the car. This is because the contestant had initially chosen
a goat and now, upon switching, has chosen the car. A loss is scored
if the resulting list contains a goat. This is because the contestant
had initially chosen the car and now, upon switching, has chosen the
goat.
from
random import randint
number_of_games
= 100000
total_wins
= 0
total_losses
= 0
for i in
range(number_of_games):
#Pick
a door.
#replace
a random value in list doors with 'choice'.
doors
= ['goat', 'goat', 'car']
choice
= randint(0, 2)
doors[choice]
= 'choice'
#Monty
shows a goat.
#if
list contains car, remove the only instance of goat.
#if
list contains 2 goats, choose one at random to be removed.
if
'car' in doors:
doors.remove('goat')
else:
doors.pop(choice)
i
= randint(0, 1)
doors.pop(i)
#Switch
doors.
#If
car is still in the list doors then a win is scored, else a loss is
scored
if
'car' in doors:
total_wins
+= 1
else:
total_losses
+= 1
print('Total
wins: ' + str(total_wins))
print('Total
losses: ' + str(total_losses))
Upon running the program with 100 000
games, the following output resulted:
Total
wins: 66878
Total
losses: 33122
This means that by switching doors the
contestant won 66878 times out of 100 000 which roughly corresponds
to winning 2/3rd of all games. WOW!
Even though every fiber of my being
hates to admit it, it turns out that switching IS better!
It just goes to show that when dealing
with probabilities, our brains (my brain at least) is ill-equipped to
understand what is really going on. But we must strive to understand
what is actually going on because it can help guide us towards making
sound decisions (Dr. N Taback, personal communication,
January 16, 2014). Through the use of tools like statistics, math and
computation we can be confident that we have found the kernel of
truth beneath our surface perceptions.