Let’s have some fun with the Monty Hall problem. The set-up is three closed doors. Behind one is a nice prize, behind the other two are dud prizes. You (having no prior knowledge) choose a door, at which point the game’s host (with prior knowledge) reveals a dud prize behind one of the doors you did not choose and asks if you want to stay with the door you chose or switch and choose the other door that is still closed.
There are many published articles on why the proper strategy is to switch doors, including the article above, but when I tried to explain this to someone a few months ago I was told that I was “full of sh*t, the odds don’t change”. Well actually the odds do change, because the game’s host has revealed new information. It all has to do with Bayes’ Theorem whose basic formula
P(A|B) = P(B|A)P(A) / P(B)
reads as follows:
The probability of event “A” occurring, given event “B” has occurred
equals
The probability of event “B” occurring, given event “A” has occurred
times
the probability of event “A”
divided by
The probability of event “B”.
Since I am apparently a failure at explaining this, I wrote an F# Monte Carlo program to do my talking for me. The F# code really expresses the way the game works. There is not much to it. Here is the type for an individual game:
It constructs each game given doorWithPrize
, randomly generated, fstChoice
, also randomly generated, and revealedDoor
the door the host opens during the game play, for which there are two rules for choosing this door.
If the player happened to choose the door hiding the real prize then the host arbitrarily chooses between the other two doors:
Otherwise the host is constrained to open one and only one of the doors:
Over a large enough sample of games the host is constrained two-thirds of the time in his choice of doors to open because the player will make the wrong first choice two-thirds of the time. So the act of exposing one of the dud prizes reveals valuable information to you the player. (At least it tells you something with better than 50/50 odds.) And that’s why this works.
For your friends who still won’t believe and think you have played some sort of trick the program comes with an audit function that will print the records of up to 100 games. The source code is available here or on GitHub. Have fun with it.
Pingback: F# Weekly #46, 2012 « Sergey Tihon's Blog
Nice one – thank you.
you should consider putting this on a site like tryfsharp.org so that you can run and see it at once
OMG – stupid me – should have checked the acutal links – sorry man … just remove (parts) of my comments … (facepalm myself hard)