Probability & Statistics

The Monty Hall Problem

Three doors, one car. The host reveals a goat and offers a switch. Should you take it, and how often does switching win?

solvedmedium3 min

You are on the game show. Three doors hide a car and two goats, and you do not know which door hides what. You pick a door. The host, who knows what is behind every door, opens one of the other two on a goat and offers to let you switch to the remaining door. He always opens a goat door, never the one you picked, and when he has a free choice he opens either goat with equal chance.

Should you switch, and what is your probability of winning the car if you switch?

Reveal solutionHide solution

Say I pick door 1 and the host opens door 3 on a goat, offering me door 2. Nothing below depends on those labels.

#The decisive observation

Switching inverts my first guess. If door 1 already hid the car, switching loses. If door 1 hid a goat, the host is forced to expose the other goat, so the door I move to must hide the car. Switching therefore wins on exactly the plays where my first pick was a goat, which is two in three.

P(switch wins)=P(first pick is a goat)=23.(1)\PP(\text{switch wins}) = \PP(\text{first pick is a goat}) = \frac{2}{3}. \tag{1}

Staying wins the remaining third. Nothing here used how the host breaks a tie, because a tie only arises when I already hold the car, and then switching loses whichever goat he shows.

#Conditioning on the open door

The strategy rate above is the number that decides the game. The probability for a named door is finer and does lean on the host's symmetry. Write CiC_i for the car behind door ii, each with prior 13\tfrac{1}{3}, and H3H_3 for the host opening door 3. His rule fixes the likelihoods.

P(H3C1)=12,P(H3C2)=1,P(H3C3)=0.(2)\PP(H_3 \mid C_1) = \frac{1}{2}, \qquad \PP(H_3 \mid C_2) = 1, \qquad \PP(H_3 \mid C_3) = 0. \tag{2}

With the car behind my door he chooses between two goats and the uniform rule gives 12\tfrac{1}{2}. With the car behind door 2 he is forced onto door 3. He can never open door 3 onto the car. Marginalising gives P(H3)=12\PP(H_3) = \tfrac{1}{2}, and Bayes returns

P(C1H3)=121312=13,P(C2H3)=11312=23.(3)\PP(C_1 \mid H_3) = \frac{\tfrac{1}{2}\cdot\tfrac{1}{3}}{\tfrac{1}{2}} = \frac{1}{3}, \qquad \PP(C_2 \mid H_3) = \frac{1\cdot\tfrac{1}{3}}{\tfrac{1}{2}} = \frac{2}{3}. \tag{3}

A host who instead opened door 3 with probability qq when free would leave P(C2H3)=11+q\PP(C_2 \mid H_3) = \tfrac{1}{1+q}. The uniform q=12q = \tfrac{1}{2} is what pulls this back to the same 23\tfrac{2}{3} as the strategy rate.

#Why the even split is wrong

The tempting picture calls the two closed doors symmetric once a goat is shown. A random opener would make them so. This host is not random. He avoids the car and avoids my door, so opening door 3 is a measurement, and that measurement moves door 3's prior mass onto door 2 while leaving my door 1 fixed at 13\tfrac{1}{3}.

#A one-line simulation

The decisive observation collapses the experiment. Switching wins exactly when the car and my first pick differ, so each game is one comparison of two independent uniform draws.

import random

def switch_wins(doors: int = 3) -> bool:
    # Switching wins exactly when the first guess missed the car.
    return random.randrange(doors) != random.randrange(doors)

Averaging this over a growing number of games drives the running estimate onto 23\tfrac{2}{3}.

Each run plays 20,000 games from a fixed seed. The running estimate of the switching win rate swings while the sample is small and settles onto 2/3 as the games accumulate. A new run replays an independent sequence, so the early path differs but the limit does not.

The same identity returns n1n\tfrac{n-1}{n} when the host clears every other goat from nn doors.