# he Monty Hall Problem

If you see nothing but text above this line, your browser probably doesn't support Java.

This is a simple riddle about probability with a highly counterintuitive answer. I got my bottom kicked over this on the WWBC discussion group some time ago during the course of an uncharacteristically rancourous and ill-humoured dispute over the correct answer. No-one EVER gets the answer right, even research science professionals who are taught about probability, and I had to have my nose rubbed in some empirical evidence before I believed it. I have become an evangelist - no fanatic like a convert, or so they say.

Let's see what you think...

Imagine you are participating in a game show. Reaching the final stage, you have the option to win a sports car. To win the car, you have to guess behind which of three doors the car is concealed. The three doors are closed, and behind two of them is ... a goat! One does not want to win a goat, of course. Unless one has a particularly close attachment to livestock... However, you don't know which door is which and there are no clues - this is a pure guess.

You pick a door...

The game-show host - let's call him Monty Hall, since he actually exists and that's his name - then crosses the studio to one of the OTHER doors and opens it, revealing ... a goat! One down, one to go. The host then asks you whether you want to stick with the door you have selected, or whether you'd like to take the opportunity to switch to the remaining unopened door.

The question is, what is your best choice at this point? Do you switch, or do you stick, and does it even make a difference?

The answer, believe it or not, is that you double your odds of winning if you switch. Your chance of winning if you stick is 1/3, and your chance of winning if you switch is 2/3. Discussions about this tend to turn bloody, which is why I started this page with an Applet to show you it actually happening. (Don't worry, I didn't believe it either.) If you stop the Applet running and step through it using the "Step" key, you can actually play the game yourself by clicking the option buttons. (Or at least you will be able to, when the implementation is ....er... implemented.)

Crucial to understanding this problem is realising that the host KNOWS which door conceals the car, and actively chooses to open a door which does not conceal it, thereby altering the constraints on your subsequent choices. Your original choice had a 1/3 probability of being a winner, and a 2/3 probability of being a stinker. If your choice is a stinker, then the host, by eliminating the remaining stinker, has GUARANTEED that you will win if you switch. If, on the other hand, your choice was a winner, the host has guaranteed that you will lose if you switch.

In this way, your probability of winning if you stick is constrained to your original 1/3 probability of having chosen right.

It works. Trust me!

## ode Snippet

This is the heart of the Applet you see above. Don't even think about asking me for the rest of the code, unless I already know you from WWBC. I spent ages getting the drop-shadows on the panels to look right, and I'm not about to give 'em away unless you pay me. This is, however, enough code to see how the whole thing works...

```void Iterate() {

m_txtCount.setLValue(m_lCount++);

int nTarget = (int)(java.lang.Math.random() * 300000) % 3;
m_cntTarget.setItem(nTarget, m_cntTarget.getItem(nTarget) + 1);

int nChosen = (int)(java.lang.Math.random() * 300000) % 3;
m_cntChosen.setItem(nChosen, m_cntChosen.getItem(nChosen) + 1);

int nOpened = 0;
if (m_bRandom) {
nOpened = (int)(java.lang.Math.random() * 300000) % 3;
}
else {
nOpened = 0;
for (int n = 0; n < 3; n++) {
if (nTarget != n && nChosen != n) {
nOpened = n;
break;
}
}
}
m_cntOpened.setItem(nOpened, m_cntOpened.getItem(nOpened) + 1);

if (nOpened == nTarget || nOpened == nChosen) {
m_txtExcluded.setLValue(m_txtExcluded.getLValue() + 1);
}
else if (nTarget == nChosen) {
//  Already right - switch to lose
m_gLoseOnSwitch.setLValue(m_gLoseOnSwitch.getLValue() + 1);
m_gWinOnStick.setLValue(m_gWinOnStick.getLValue() + 1);
}
else {
//  Not right - switch to win
m_gWinOnSwitch.setLValue(m_gWinOnSwitch.getLValue() + 1);
m_gLoseOnStick.setLValue(m_gLoseOnStick.getLValue() + 1);
}

double dStick = (double)m_gWinOnStick.getLValue() / m_lCount;
double dSwitch = (double)m_gWinOnSwitch.getLValue() / m_lCount;

m_gProbabilityWinOnSwitch.setDValue(dSwitch);
m_gProbabilityWinOnStick.setDValue(dStick);

m_optGuess[nTarget].setLabel(m_fmt.format(m_cntChosen.getItem(nTarget)));
m_optShow[nTarget].setLabel(m_fmt.format(m_cntOpened.getItem(nTarget)));
m_optGuessAgain[nTarget].setLabel(m_fmt.format(m_cntChosen.getItem(nTarget)));
m_optWas[nTarget].setLabel(m_fmt.format(m_cntTarget.getItem(nTarget)));

Render(false);
}
```