The Monty Hall Problem: Why Switching Doors Doubles Your Chance of Winning
Prerequisite:The Collatz Conjecture: A Problem You Can State in Three Lines and Nobody Can Solve
0. Key points
Section titled “0. Key points”- Behind one of three doors is a car, behind the other two are goats. After you pick a door, the host always opens one of the remaining doors, and always one with a goat behind it. If you then switch, your chance of winning rises from to — it doubles.
- The reason, in one sentence: “switching wins” and “the first pick was wrong” are the same event. The probability of picking wrong at the start is , so the switching strategy wins with probability .
- We derive the same conclusion from conditional probability (Bayes’ theorem). The information carried by the door the host opens does not update the probability of your own door (it stays at ); it pushes only the probability of the remaining door up from to .
- The problem caused an uproar not because the answer is hard, but because the statement of the problem did not spell out the rules. Change the host’s behaviour slightly and the correct answer becomes , or , or .
- In general, if you pick one of doors and the host opens goat doors, your original door stays at while each remaining door carries . For , the switching strategy wins with probability .
1. Motivation: a television show and ten thousand letters of protest
Section titled “1. Motivation: a television show and ten thousand letters of protest”American television had a long-running show called Let’s Make a Deal, hosted by a man named Monty Hall. One segment of that show, recast as a mathematics problem, has become the most famous anecdote in all of probability theory.
The problem goes as follows.
Three doors stand in front of you. Behind one is a new car; behind the other two are goats. You pick a door. The host, who knows where the car is, then opens one of the two doors you did not pick — one with a goat behind it — and asks: “Would you like to change your choice?”
Should you switch?
Almost everyone answers: “Two doors are left, so it is fifty-fifty. Switching makes no difference.” That was my own first answer too. But the correct answer is switch, and the chance of winning is not fifty-fifty at all: it is exactly twice the chance of staying.
The gap between this answer and intuition caused an incident in 1990. In her Parade magazine column “Ask Marilyn”, Marilyn vos Savant answered “you should switch”, and roughly ten thousand letters of protest arrived. Close to a thousand of them came from people holding doctorates. Letters in the tone of “you are wrong” and “this is what happens when people who do not understand probability write about it” arrived on university mathematics department letterhead. Experts overlooking an error together is in fact not so rare. In the case of the four colour theorem, a faulty proof was believed correct for eleven years (where Kempe went wrong(Remark 4.4)[The Four Color Theorem]).
There is an even more striking anecdote. Paul Erdős, one of the great mathematicians of the twentieth century, is said to have refused to accept a verbal explanation and to have yielded only after being shown the output of a computer simulation. (Paul Hoffman’s biography The Man Who Loved Only Numbers records this on the testimony of Andrew Vázsonyi.) A man who thought about prime numbers more deeply than anyone else, tripped up by a problem with three doors. Few examples show so vividly that the difficulty of mathematics is not merely a matter of computational effort. (On the question of why mathematics is hard, see Why mathematics is hard, which treats another example of probabilistic intuition going astray in the birthday problem(Proposition 6.2)[Why Mathematics Is Hard].)
The problem itself was posed in 1975 by the statistician Steve Selvin in a letter to The American Statistician, and further back it has essentially the same structure as the “box paradox” published by the French mathematician Joseph Bertrand in 1889 (Example 4.3). It is, in other words, a venerable trap that has been defeating human intuition for over a century.
In this article we prove the answer completely, in two ways: first by the naive but certain method of writing out every case, then by conditional probability and Bayes’ theorem. After that we take up a deeper question: why did this problem cause such a fight? The answer, stated in advance, is that the cause lay not in the mathematics but in the English.
2. Preliminaries: translating the rules into mathematics
Section titled “2. Preliminaries: translating the rules into mathematics”When an argument about a probability problem gets heated, it is usually because “what is random, and with what probability” was left vague while the discussion moved on. So we begin by rewriting the everyday-language rules in a form that admits no interpretation at all. Doing this carefully is the single most important step in the whole article. It is exactly the same move as defining the value of an infinite decimal(Definition 2.2)[Is 1 Equal to 0.999…? Fixing the Meaning of an Infinite Decimal First] before answering the question “is equal to ?”.
Definition 2.1(The Monty Hall problem (standard rules))
Label the doors . We call a probability model satisfying the following five conditions the standard rules of the problem.
- The position of the car is uniformly distributed: . Behind the other two doors are goats.
- The contestant’s first pick is independent of (the contestant has no information about where the car is).
- The host knows both the position of the car and the contestant’s pick , and the door he opens always satisfies and . That is, the host never opens the contestant’s door and never opens the car’s door.
- If two doors satisfy condition 3 (that is, if ), the host chooses between them with probability each.
- The host always opens exactly one door and afterwards always asks “would you like to switch?”. He does not decide whether to open a door based on how the contestant looks.
Conditions 4 and 5 are the parts that the everyday-language statement left out. Without stating them the problem cannot be solved. Later, in Proposition 5.1 and Proposition 5.4, we shall see how the answer changes when these two are broken.
Definition 2.2(The two strategies)
A strategy for the contestant is a rule determining which door is finally chosen after the host has opened a door. We consider only the following two.
- Stay: keep the final choice equal to .
- Switch: make the final choice the unique door that is neither nor .
For either strategy, its win probability is the probability that the car is behind the door finally chosen.
Let us check that the final choice of the switching strategy really is determined as “the unique door”. There are three doors and , so removing and leaves exactly one. The instruction “switch” is therefore unambiguous.
Finally we fix notation for conditional probability. It is exactly the definition taught in high school.
Definition 2.3(Conditional probability and Bayes' theorem)
For an event with , the conditional probability of given that has occurred is defined by
In particular, if are mutually exclusive, is the whole sample space, and for every , then the law of total probability
and Bayes’ theorem
hold.
The proviso at the start of this definition cannot be dropped, because there is no value one can assign to a division whose denominator is (a nonzero number cannot be divided by zero(Proposition 3.2)[Why You Cannot Divide by Zero]). In the computations below, every time we write a conditional probability we check that the conditioning event has positive probability.
Bayes’ theorem has an intimidating name, but all it does is reorder a computation with fractions. It reads in two ways — ” occurs, and then occurs” and ” occurs, and of that the part where holds” — and sets the two readings equal.
3. Method 1: write out every case
Section titled “3. Method 1: write out every case”We start with a proof that uses almost no machinery. A secondary-school student should be able to follow it.
Proposition 3.1(Win probability of the staying strategy)
Under the standard rules of Definition 2.1, the staying strategy wins with probability .
Proof(Proposition 3.1)
Winning with the staying strategy means that the car is behind the finally chosen door , that is, that the event occurs. The host’s action has no bearing whatsoever on whether this event occurs: what lies behind the doors was fixed before the contestant chose, and opening some other door does not change what is behind door .
So we compute . By condition 2 of Definition 2.1, and are independent, and by condition 1, is uniform, so
In the second equality we used independence (), and in the last one . Hence the staying strategy wins with probability .
What deserves attention in this proof is that whatever the host does, the does not move. Many people reason “there are only two doors left, so it must have become ”, but what decreased was the number of doors, not the contents of the door you first picked. The number was fixed the moment you chose: it is the probability of hitting the right one of three doors blindfolded.
Theorem 3.2(Win probability of the switching strategy)
Under the standard rules of Definition 2.1, the switching strategy wins with probability . It is therefore exactly twice as likely to win as the staying strategy (Proposition 3.1).
Proof(Theorem 3.2)
The key is the following equivalence.
Claim: the switching strategy wins if and only if (the first pick was wrong).
() Suppose . Then the car’s door is not the door the contestant chose. Moreover by condition 3 of Definition 2.1, so it is not the door the host opened either. Since the final choice of the switching strategy is “the unique door that is neither nor ”, that door is precisely . Hence switching wins.
() We prove the contrapositive. If , then the finally chosen door differs from and hence also from . So switching loses.
The claim being proved, the win probability of the switching strategy is . In the proof of Proposition 3.1 we computed , so
The only thing actually used in the proof is the single point that if you picked wrong at the start, the host has no choice but to open the one remaining goat. This situation, in which the host has no freedom, is the moment at which information leaks. The host moves under the constraint “anything but the car”, and his movement therefore tells you where the car is.
Put differently, the host did not “show you a goat”; he told you which of the other two doors is the promising one. The two doors you did not pick carry a combined probability of . The host set one of those two to zero, so the whole collects on the other.
Example 3.3(Counting every case in a table)
For those who would rather count than argue, here is a table of all the cases. By condition 2 of Definition 2.1, the situation is symmetric in the contestant’s choice, so we may fix (you picked door 1). The remaining split is into three cases according to the position of the car.
| Position of the car | Its probability | Door the host opens | Stay | Switch |
|---|---|---|---|---|
| 1 | 2 or 3 ( each) | win | lose | |
| 2 | 3 (no other option) | lose | win | |
| 3 | 2 (no other option) | lose | win |
Staying wins only in the first row, with probability ; switching wins in the second and third rows, with probability . This is exactly Proposition 3.1 and Theorem 3.2.
Splitting into four cases so as to include the host’s choice, the probability tree looks as follows.
flowchart LR S["You pick door 1"] S -->|"1/3"| A["Car is behind door 1"] S -->|"1/3"| B["Car is behind door 2"] S -->|"1/3"| D["Car is behind door 3"] A -->|"1/2"| A2["Host opens door 2"] A -->|"1/2"| A3["Host opens door 3"] B -->|"1"| B3["Host opens door 3"] D -->|"1"| D2["Host opens door 2"] A2 --> R1["Switching loses<br/>probability 1/6"] A3 --> R2["Switching loses<br/>probability 1/6"] B3 --> R3["Switching wins<br/>probability 1/3"] D2 --> R4["Switching wins<br/>probability 1/3"]
4. Method 2: measuring the update of information with Bayes’ theorem
Section titled “4. Method 2: measuring the update of information with Bayes’ theorem”What Theorem 3.2 computed is the win probability when you decide “I will switch” before the game begins. A real contestant, however, decides after seeing which door the host actually opened. Once the information “door 3 has been opened” arrives, what are the probabilities of doors 1 and 2? Computing this is the job of Bayes’ theorem.
Theorem 4.1(Probabilities after observing the host's action)
Under the standard rules of Definition 2.1, suppose the contestant picks door 1 () and the host opens door 3 (). Then
Consequently, in this situation the switching strategy (choosing door 2 instead) wins with probability .
Proof(Theorem 4.1)
Below, every probability is conditioned on , but we suppress from the notation to avoid clutter.
Step 1: prior probabilities. By conditions 1 and 2 of Definition 2.1,
Step 2: likelihoods (the probability that the host opens door 3 in each case). There are three cases.
- . The host cannot open door 1 (the contestant’s pick), and the car is there as well. He can open door 2 or door 3, and by condition 4 of Definition 2.1 he chooses between them with equal probability. Hence .
- . The host can open neither door 1 ( by condition 3) nor door 2 ( by condition 3). Only door 3 remains. Hence .
- . The host does not open door 3, where the car is (condition 3). Hence .
Step 3: find by the law of total probability. Apply the law of total probability from Definition 2.3 with the exclusive partition :
Step 4: Bayes’ theorem. By Definition 2.3,
The three sum to , consistent with being probabilities.
Switching in this situation means choosing door 2, so its win probability is .
Looking inside the computation makes it clear where the factor of comes from. The priors were level, both . What created the difference was the likelihoods. In the world where the car is behind door 1, the host opens door 3 with probability (he picks on a whim); in the world where the car is behind door 2, with probability (he has no alternative). This ratio carries straight over to the ratio of the posteriors.
The Bayesian point is that one and the same observation, “door 3 was opened”, is explained better by the door-2 hypothesis than by the door-1 hypothesis. By the same logic that makes “the person who must have been there at that hour” a stronger suspect than “the person with no alibi”, the hypothesis that best explains the evidence gains points. The number is the exchange rate: door 2 becomes suspicious in proportion to how little freedom the host had.
Example 4.3(Bertrand's box (1889))
Let us compute a classical problem with the same structure. There are three boxes, each containing two coins. Box contains two gold coins, box two silver coins, and box one gold and one silver. You choose a box at random and draw one coin at random from it; it turns out to be gold. What is the probability that the other coin is also gold?
It is tempting to answer: “since a gold coin came out, the box is either or , so .” This is wrong. Writing for the event “the coin drawn is gold”, we apply Bayes’ theorem from Definition 2.3. The priors are for each box, and the likelihoods are
By the law of total probability,
Therefore
The probability that the remaining coin is also gold is . Note that this is identical to Theorem 4.1 in both structure and numbers. The error “two options remain, hence ” has been catching humanity in exactly the same shape for more than 130 years.
5. Change the rules and the answer changes
Section titled “5. Change the rules and the answer changes”Here is where the problem becomes genuinely interesting. The mathematicians who got it wrong in 1990 did not do so because they were ignorant of probability. Because the statement of the problem failed to specify conditions 4 and 5 of Definition 2.1, each of them was solving a different game in his head. And indeed, a small change to the conditions changes the correct answer.
5.1. A host with a habit
Section titled “5.1. A host with a habit”First we break condition 4 (a fair coin when in doubt). What happens if the host has a habit of preferring to open the higher-numbered door whenever he has a choice?
Proposition 5.1(A biased host)
Keep conditions 1, 2, 3 and 5 of Definition 2.1 and replace condition 4 by the following. When the contestant picks door 1 () and the car is also behind door 1 (), the host opens door 3 with probability and door 2 with probability , where is a constant. Then
so in the situation where the host has opened door 3, switching wins with probability . Likewise, in the situation where the host has opened door 2, switching wins with probability . On the other hand, the win probability of the switching strategy measured before the game begins is always , whatever the value of .
Proof(Proposition 5.1)
Below we condition on and suppress it from the notation. The likelihoods are as follows.
- (this is the assumption itself).
- (by condition 3 neither door 1 nor door 2 can be opened, so only door 3 is available).
- (by condition 3 the car’s door is never opened).
By the law of total probability from Definition 2.3,
Since we have , so the conditional probabilities are defined. By Bayes’ theorem,
Switching in this situation means choosing door 2, so the win probability is .
The case where the host opens door 2 is analogous. From , and we get , and
Even when we have , so this too is defined, and its value is .
Finally we check the win probability before the game starts. The “claim” in the proof of Theorem 3.2 uses condition 4 nowhere (it uses only from condition 3 and the fact that there are three doors). Hence switching wins if and only if , and the probability of that is determined by conditions 1 and 2 alone to be . Indeed, adding the two situations with their weights,
which agrees.
Corollary 5.2(Switching never loses you anything)
In the setting of Proposition 5.1, whatever the value of the host’s habit and whichever door he opened, the switching strategy wins with probability at least . Equality holds only when and the host opened door 3, or when and the host opened door 2.
Proof(Corollary 5.2)
In the situation where the host opened door 3, the win probability is by Proposition 5.1. From we get , and taking reciprocals (which reverses the inequalities, these being inequalities between positive numbers),
The left equality holds only when , that is .
In the situation where the host opened door 2, the win probability is . From we get , so likewise , with left equality only when , that is .
The practical conclusion is this: even without knowing the host’s habit, switching is always a move that is no worse. Even in the worst case () switching merely drops to even odds; it never loses on balance. This general formula was pointed out by Morgan et al. in The American Statistician in 1991, and it exposed the fact that the naive answer actually depends on condition 4.
Morgan et al. observed that “the answer tacitly assumes that the host tosses a fair coin”. Conversely, once the standard rules are made explicit, is entirely correct. Most of the 1990 controversy was therefore not a mathematical error but a failure to agree on the setting of the problem. This is what happens when a mathematical problem statement omits an “obviously reasonable assumption”.
5.2. A host who knows nothing
Section titled “5.2. A host who knows nothing”Next we break condition 3 (the host knows where the car is). Suppose the host is new on the job, opens a door at random without knowing where the car is, and it happens to reveal a goat. This is often called the “Monty Fall” problem.
Proposition 5.4(With an ignorant host the odds are even)
Keep conditions 1 and 2 of Definition 2.1 and replace conditions 3 and 4 by the following. After the contestant picks door 1, the host, not knowing where the car is, chooses one of doors 2 and 3 with probability each and opens it (so the car may be revealed). Then, conditioned on “a goat appeared behind the door the host opened”,
so the switching strategy wins with probability .
Proof(Proposition 5.4)
Write for the event ” and a goat appeared behind the opened door”. We compute the joint probability with for each value of . The host’s choice is independent of , and the probability that is always .
- . There is a goat behind door 3, so .
- . There is a goat behind door 3, so .
- . Opening door 3 reveals the car, so does not occur: .
Hence , and by Definition 2.3,
Switching means choosing door 2, so its win probability is .
Placing Theorem 4.1 and Proposition 5.4 side by side makes the difference plain. Under the standard rules we had , whereas with an ignorant host this drops to . The constraint that the host avoids the car was the source of the information. Remove the constraint and the information disappears, and the intuitive answer becomes correct.
So the people who insisted on were not entirely wrong. They were solving the Monty Fall problem. At least part of those ten thousand letters concerned not mathematics but reading comprehension.
6. More doors: the moment intuition becomes right
Section titled “6. More doors: the moment intuition becomes right”The explanation that works best on those who cannot swallow is to increase the number of doors to a hundred. We first prove the general case and then look at a hundred doors as a special case of it.
Theorem 6.1(The case of n doors)
Let and . The car is behind one of doors, and its position is uniformly distributed. The contestant picks door 1. The host knows where the car is and opens of the doors the contestant did not pick, choosing only doors without the car. The set of doors he opens is chosen uniformly among all -element sets satisfying that condition.
Then, after observing the set that the host actually opened,
In particular, the strategy of switching to one uniformly chosen unopened door other than the original wins with probability .
Proof(Theorem 6.1)
First the likelihoods. Let be a -element subset of .
- . The host may choose any doors from ( doors), so there are choices, whence .
- with and . The host chooses doors from ( doors), so .
- with . The host never opens the car’s door, so .
Let us record a relation between the two binomial coefficients:
(Since , the binomial coefficient on the right is meaningful.) Taking reciprocals of both sides,
We call this identity the coefficient relation in what follows.
Next we use the law of total probability from Definition 2.3. There are doors other than that are not in , so abbreviating and applying the coefficient relation to the first term,
Along the way we used . Since gives , we have and the conditional probabilities are defined.
By Bayes’ theorem,
As a check: there are unopened doors other than , so the probabilities total
which is consistent. Since all the other unopened doors carry the same probability, switching to one of them wins with probability .
Substituting , gives and a switching win probability of , reproducing Theorem 4.1. Note that for general as well, the structure survives intact: the probability of the door picked first does not move from .
Example 6.2(A hundred doors)
Take and . You pick one door (door 1) out of a hundred. The host then opens, one after another, 98 of the remaining 99 doors, all without the car. At the end only two are left: your door 1 and the single door the host stubbornly refused to open.
By Theorem 6.1, , so
Switching wins with probability .
In this setting nobody hesitates, because the fact that “the host opened 98 doors and yet obstinately left that one alone” is too eloquent to ignore. With three doors, the host leaves only one door unopened, so this “unnaturalness” is hard to see. That is the whole difference. What happens for is not one bit different from what happens for ; it is merely that has been diluted to .
7. Exercises
Section titled “7. Exercises”Exercise 7.1Easy
Suppose there are four doors, with a car behind one and goats behind three. The car’s position is uniformly distributed and you pick door 1. The host knows where the car is and opens exactly one of the three doors you did not pick, choosing only a door without the car (choosing uniformly when several doors are available).
Find (1) the probability that the car is behind door 1, and (2) the win probability if you switch to one of the two unopened doors chosen at random. Should you switch?
Solution
Apply Theorem 6.1 with , . The condition holds, so the theorem applies.
(1) .
(2) There are other unopened doors, each with probability
Switching to either one wins with probability . As a check, , which is consistent.
Since , you should switch. The effect is less dramatic than the of the three-door case, because two doors are left closed and the probability is spread over both.
Exercise 7.2Standard
Take the setting of Proposition 5.1 with . That is, the host has the habit of always opening door 3 whenever the car is behind your door 1 and he has a choice (and you know about this habit).
(1) Find the win probability of switching when the host opens door 3. (2) Find the win probability of switching when the host opens door 2. (3) Verify that the weighted average of (1) and (2), with the probabilities as weights, is .
Solution
(1) By Proposition 5.1 the win probability is . Checking directly: , , , so and . Switching gives even odds.
(2) By Proposition 5.1 the win probability is . This is only natural: if a host with opens door 2, then an event impossible in the world where the car is behind door 1 has occurred (). So the car is certainly behind door 3, and switching wins for sure.
(3) Since and ,
This agrees with the pre-game win probability (the proof of Theorem 3.2 does not use condition 4). A host with a habit does not change the total amount of winning probability; he only skews its distribution across the situations.
Exercise 7.3Standard
In the ignorant-host setting of Proposition 5.4, find the following.
(1) The probability that the door the host opens reveals the car. (2) The win probabilities of staying and of switching, conditioned on “a goat appeared”. (3) The proportion of the time the contestant obtains the car by switching, when the game is repeated from start to finish (including the rounds in which the car is revealed).
Solution
Suppose the contestant picks door 1 and the host opens door 2 or door 3 with equal probability.
(1) The car is revealed when it is behind door 2 or door 3 and the host opens exactly that door:
(2) By Proposition 5.4, conditioned on a goat appearing, both staying and switching win with probability . (In Proposition 5.4 we computed the case where door 3 was opened, but the case of door 2 is the same computation with the labels exchanged.)
(3) Counting a round in which the car is revealed as a loss for the contestant, switching wins exactly when a goat appears and the switch is correct. By (1) a goat appears with probability , and given that, the switch is correct with probability by (2), so
With no host to carry information, the win probability falls back to the of a blind guess. The of Theorem 3.2 was a bonus given by the host’s constraint of avoiding the car.
Exercise 7.4Hard
The three prisoners problem (introduced by Martin Gardner in 1959). Three prisoners A, B and C have been sentenced to death, but it has been decided that exactly one of them will be pardoned. Who is pardoned is determined uniformly at random, and only the warden knows.
Prisoner A asks the warden: “At least one of B and C must be executed. Tell me the name of one who will be executed. Hearing it cannot add any information about my own fate.” The warden agrees and answers by the following rule: if exactly one of B and C is to be executed (that is, if the other is pardoned), he names the one to be executed; if both B and C are to be executed (that is, if A is pardoned), he names B or C with equal probability.
When the warden answers “B will be executed”, find the probability that A is pardoned and the probability that C is pardoned. Was A’s reasoning correct?
Solution
Let be the person pardoned and the name the warden gives. The priors are . We read off the likelihoods from the rule.
- . Both B and C are executed, so the warden chooses with equal probability: .
- . The warden does not name B, who is pardoned (by the rule he names one to be executed): .
- . Of B and C, only B is executed, so the warden must say B: .
By the law of total probability from Definition 2.3,
By Bayes’ theorem,
A’s reasoning was half right. His own probability of pardon did indeed stay at , neither rising nor falling. But C’s probability jumped from to . It is not that no information appeared; rather, all the information flowed into C.
This problem has exactly the same structure as Theorem 4.1. The correspondence is “A = the door you picked first”, “B, whom the warden named = the door the host opened”, “C = the door left over”. The warden does not name A () and does not name the person pardoned (). Even the numbers, and , are identical.
References
Section titled “References”- S. Selvin, “A problem in probability (letter to the editor)”, The American Statistician 29 (1975). The letter that first put the problem in print; a follow-up the same year, “On the Monty Hall problem”, gives the solution.
- J. P. Morgan, N. R. Chaganty, R. C. Dahiya, M. J. Doviak, “Let’s make a deal: The player’s dilemma”, The American Statistician 45 (1991), 284–287. The source of Proposition 5.1 (win probability ) in this article.
- Jason Rosenhouse, The Monty Hall Problem: The Remarkable Story of Math’s Most Contentious Brain Teaser, Oxford University Press, 2009. A book-length treatment covering the classification of variants, psychological studies and the history of the controversy.
- Marilyn vos Savant, The Power of Logical Thinking, St. Martin’s Press, 1996. Her own compilation of the 1990 column and the letters it drew.
- Paul Hoffman, The Man Who Loved Only Numbers, Hyperion, 1998. Contains the anecdote of Erdős refusing to accept the answer.
- William Feller, An Introduction to Probability Theory and Its Applications, Vol. I, 3rd ed., Wiley, 1968 — Chapter V (conditional probability and independence). The classical textbook treatment of Bayes’ theorem and of what happens when it is misused.
Appendix: checking by simulation
Section titled “Appendix: checking by simulation”Trying for yourself the method that convinced Erdős. If the proofs still leave you unsatisfied, the sure remedy is to make a computer play a million games. The following code runs on the Python standard library alone.
import random
def trial(switch, n_doors=3): """Play one round; return True if it is a win.""" doors = range(n_doors) car = random.randrange(n_doors) pick = random.randrange(n_doors) # the host opens, uniformly, one door that is neither the pick nor the car openable = [d for d in doors if d != pick and d != car] opened = random.choice(openable) if switch: pick = next(d for d in doors if d != pick and d != opened) return pick == car
random.seed(2026)n = 1_000_000for switch in (False, True): wins = sum(trial(switch) for _ in range(n)) print(f"switch={switch}: {wins / n:.4f}")Staying comes out around and switching around . With a million rounds the statistical fluctuation settles down around the third decimal place.
But this experiment is meaningful only because the proof of Theorem 3.2 is already in hand. The experiment itself is no substitute for a proof. There are problems, such as the Collatz conjecture, that have been verified for every number up to and yet remain open (the state of computational verification(Remark 7.3)[The Collatz Conjecture]).
Where the mathematics sits in the code. The line to look at is the one that builds openable. Writing d != car there is exactly condition 3 of Definition 2.1 (the host does not open the car’s door). Drop that condition, rewriting the line as
openable = [d for d in doors if d != pick]and discard as “void” the rounds in which opened == car, and you obtain the ignorant host of Proposition 5.4; the switching win probability falls to about . Seeing in code that a single conditional expression separates from is perhaps the greatest lesson of this problem.
Adding doors. Set n_doors=100 and rewrite the code so that the host opens 98 doors, and the of Example 6.2 is reproduced. Since the code above has the host open only one door, for the -door version you should select 98 doors from openable with random.sample. Running the experiment once you already know the answer gives you a tangible feel for the fact that probability really is a long-run proportion.
Report an error in this article ・Operated by: Mugen Giken LLC ・Pricing ・Terms ・Legal notice
© 2026 夢現技研合同会社 ・Feeding the text to an LLM is welcome. Code samples are MIT licensed.