James Tauber

journeyman of some

blog > 2007 > 06 > 19 >

Monty Hall Python

The Monty Hall Problem is one of my favourite examples of a counterintuitive solution in mathematics.

It works as follows:

Now, the counterintuitive solution is that you double your chances of winning by switching. This is counterintuitive because Monty opening one door hasn't told you anything new about which of the two remaining closed door is likely to have the car behind it.

Here's how I think about it mathematically: when you pick your door, there is a 1/3 chance it's behind the door you picked and a 2/3 chance it's behind one of the other two doors. When Monty opens one of the doors, he hasn't changed that fact: there's still a 2/3 chance it's behind one of the two doors you didn't pick. It's just now he's narrowed down which of the two doors it could be behind. So there's a 2/3 chance it's behind the door you didn't pick that's still closed as opposed to a 1/3 chance it's behind the door you original picked. So you double your chances by switching.

Sound convincing? Well, some people still like to see it played out. So here is a little Python program that will play 1000 games and show you the proportion that would be won by a stayer and the proportion that would be won by a switcher.

Comments (16)

Richard Giles on June 19, 2007:

OK.....so I'm no mathematician, and I've heard this math theory before, and I still don't agree with it :).

Theoretically I can see how it pans out. But does it really work out like that practically?

Realistically, if someone picks a door, and one of the others is revealed not to contain the car, the door originally had a 50/50 chance anyway......surely.

James Tauber on June 19, 2007:

That's why I wrote the program, Richard. For the doubters like yourself :-)

Richard Giles on June 19, 2007:

Dang it. Have run it, and I still can't believe it :).

James Casbon on June 19, 2007:

I think an interesting comparison is with Deal or no Deal. Turns out exactly the same situation has different probabilities depending on the hosts prior knowledge:
http://www.machine-envy.com/blog/2006/12/26/deal-or-no-deal-vs-monty-hall/

You can also see my script that proves this. Unfortunatelywordpress has deindented it, so play along at home by providing the correct indentation.

Ken R on June 19, 2007:

Very interesting, thanks for writing the program. I found peace by thinking of it this way.

If there are three choices and you choose 1, you have a 1/3 chance of picking the correct door. Revealing one of the other doors as being wrong does not increase your odds of having picked the correct one. So the odds of picking the right door with the original pick are 1/3. Which leaves the remaining doors with a collective 2/3 chance of being correct. Since Bob has been kind enough to remove an incorrect door from the remaining set the odds of the other unopened door being correct have to be 2/3. Perhaps not as clear an explanation as James gave but it works for me :)

DavidM on June 19, 2007:

A good explanation is that if you reverse the order of the events does it change your choice?

1. You pick door number 1
2. Monty offers you the choice of keeping your door or switching to the *other two*.
3. Obviously you switch since two doors are better than one.
4. Monty then opens one of your doors which is empty.

You are still left with a better chance of getting the prize.

Its funny no matter how much I explain this my brother and wife just can't grasp it.

n[ate]vw on June 19, 2007:

I find the Wikpedia (http://en.wikipedia.org/wiki/Monty_Hall_problem) explanation most intuitive, though it's only subtly different than above. In short, there's a 2/3 chance you pick a brown Zune, and then the host reveals the other Zune. The iPhone must be behind the other door, provided you correctly guessed the Zune first.

Mike on June 19, 2007:

Wrong, wrong wrong.

The probability of the car being behind the door you picked changes when Monty reveals a door. It changes from 33% to 50%. The door that was not opened by Monty has its probability changed from 33% to 50%. The door Monty opened has changed from 33% to 0%.

If you think the door that Monty showed you has a chance, you're smoking something.

James Tauber on June 19, 2007:

Mike, did you run the script?

Tim on June 19, 2007:

The thing that can throw you off is that as stated the problem makes it sound like Monty is picking his door at random. However he knows what is behind each door, in order to not open the prize door.

This means he is providing you with some information about the doors you didn't pick (which one definitely does not have the prize), whereas he gave you no information about the door you originally picked.

I think if they made it explicit that Monty knows what is behind every door, then a lot less people would find this unbelievable.

Justin on June 20, 2007:

Easiest way for me to think about this is that there are only two choices you can make(stay, switch to remaining closed door) and
* you win by staying if and only if you were right in the first place (1/3)
* therefore your only other option, switching, must have a 2/3 chance of winning.

David Niergarth on June 20, 2007:

Running/reading the program will make a believer out of you -- very enjoyable!

The doubters will be left asking "It works in practice but what about in theory?"

msh210 on June 26, 2007:

Another way of thinking about the Monty Hall problem (for doubters) is to switch the scenario, as follows:

The contestant is offered 100 doors and told there's a prize behind one of them and nothing behind the others. He picks one (say, door number 47). The host, Monty Hall, then eliminates 98 of the doors, leaving only door number 47 and door number 71. He tells the contestant the prize is behind one of these doors. Should the contestant switch?

Of course he should. The reason is (intuitively, not mathematically): The reason door 47 is still there is that the contestant chose it, while the reason door 71 is still there is that the host chose it. So door 71's being there has more information attached to it, in some sense: someone smarter (more knowledgeable) decreed that it should remain an option.

I hope that this helps.

blamwellamum on Aug. 8, 2007:

This problem really is just a problem of semantics. Think of it this way, as a three-player game between you, Mr. Switcher, and Monty. You pick first and have a 1/3 chance of winning and a 2/3 chance of loosing. That means that the set of (Switcher, Monty) has a 2/3 chance of winning. But what we do know is that Monty has a 100% chance of loosing so Switcher will win 2/3 times. Switcher really just represents your chance of loosing and his odds off winning are directly proportional to your chance of loosing.

Still not convinced? Half the audience is screaming switch! Switch Switch! The other half is screaming stay! Stay! Stay! You would lead us to believe you have a greater chance of winning if you go with switch, but if you guess who is right, you only guess right 50% of the time :)

Add this and see:

guess = random.choice([stayer,switcher])

if car_behind == guesser: self.guess_count += 1

.
.
.
stay = 33%, switch = 66%, guess = 50%

Mr Who on Jan. 1, 2008:

Oh My Gosh i understand it now. Thanks for the 1 out of 100 example. That just explained it to me entirely. except msh210, i think it is more mathematically. What are the chances that number 47 is the right box? 1 out of 100? That is the probability that you start with. number 47 still has a 1% chance of containing the prize. The host eliminates all the others leaving 2 numbers, yours and 71, using ur example... so 71 would have a 99% chance of being the right box.

Created: June 19, 2007
Last Modified: June 19, 2007
Author: James Tauber