A Car Behind the Door, Two Approaches

Aug 03, 2026 / 5 min read

The Monty Hall problem

Say you are on a show and there are 3 doors, one of them has a car behind it, other two, goats. You made your choice, door 1, then the host opened door 2, revealing a goat behind it. Now he asks you do you want to stick with your choice or instead change your choice to door 3?

Couple of years ago, I read this problem from a book and was intrigued by it, the next day I talked to my colleague about it, he just could not understand why it is better for the player to change his position. Back then I had a vague idea or hunch of why the player should change his position. But I realize I cannot explain it, either to my colleague or myself. I probably didn’t actually understand it as much as I thought I do.

By the way the book is Why Smart People Make Big Money Mistakes by Gary Belsky, it is using Monty Hall problem as an example to show how overconfidence could bias people. Which I myself was probably an example, not the title part, I don’t have big money to lose, either. Just the overconfidence. I thought I understand it util I needed to explain it.

The Python Code that Doesn’t Need to Run

The first solution I came up with is by writing code to simulate it, as a programmer, this is what I do. But I also said “Doesn’t Need to Run”, then why are you writing the code you might ask. I’ll show.

python ///
import random
trials = 100000

samples = []
doors = [0, 0, 1]

# creates samples
for _ in range(trials):
    random.shuffle(doors)
    samples.append(doors[:])
 
wins = 0
# assume player opens door 0
for sample in samples:
    if sample[0] == 1:
        # car is behind door 0, host will open either door 1 or 2, doesn't matter 
        # because both have no car, so the player will not get the car
        # after he change his choice in either case.
        continue
    elif sample[1] == 1:
        # car is behind door 1, host will open door 2(he opens a door that reveals a goat not car), 
        # the player will switch to door 1, that is where car sits behind
        wins += 1
    elif sample[2] == 1:
        # car is behind door 2, host will open door 1, player 
        # will switch to door 2, again, he will get the car
        wins += 1
  
print(f"chance of winning after change position: {wins / trials}")

Assume we have door 0, 1, 2, and player initially chose the door 0. We are using it as the index to get the value from listsdoors, which indicates whether there is a car behind that door, the value is 1 if true otherwise the goat 0. Because the car could be behind any of them with equal chance, we can simply shuffle the doors to get different situations. Now after you wrote down the code, you can just run it to get the value of course — which apparently goes against the title. Reasoning of the code is in the comments.

But if you look closely you will notice something interesting. There are 3 branches in the simulation loop, corresponds to 3 possible positions of the value 1 in the list, which all have equal probability $\frac{1}{3}$ of happening, among them, two of three branches increment the variablewins, without even needing a real machine to do the simulation for you, the answer is right there in front of your face, a trivial $\frac{2}{3}$ .

The Boring but Important Formula

Another one is more mundane, boring approach, but nonetheless I like it as well, simply because it makes me feel educated — I never had formal education on probability. I got this solution quite recently after I learned the Bayes’ theorm form Sheldon Ross’s book, eagerly wanted find something to apply.

For the convenience we will use door A, B, C.

Let $P(A)$, $P(B)$, $P(C)$ be the chance that car is behind door A, B, C respectively.

You initially chose door A, and given the event $E$ host opens door B happened, door C will be your only choice if you chose to change, the probability of you getting the car is equivalent to asking the possibility of a car behind door C at this point.

$$ P(C|E) = \frac{P(E|C)P(C)}{P(E)} $$

We know that $P(C) = \frac{1}{3}$.

For $P(E|C)$, given the car is behind door C, the chance of the host opening door B, because the player already chose door A and the host opens a door that reveals a goat, thus cannot be door C which has a car behind it. This leaves door B his only choice, thus $P(E|C)=1$.

The probability of host opening door B:

$$ P(E) = P(E|A)P(A) + P(E|B)P(B) + P(E|C)P(C) $$

We already knew $P(E|C)=1$.

$P(E|B)$, chance of host opening door B when there is a car behind door B is 0.

$P(E|A)$, when the car is behind door A, chance of host choosing door B is $\frac{1}{2}$, since the host can open either B or C.

Now we get:

$$ \begin{aligned} P(E) &= \frac{1}{2} \cdot \frac{1}{3} + 0 \cdot \frac{1}{3} + 1 \cdot \frac{1}{3} = \frac{1}{2} \\ P(C|E) &= \frac{1 \cdot \frac{1}{3}}{\frac{1}{2}} = \frac{2}{3} \end{aligned} $$

I think one of the tricky part of the problem is that is says that “the host opened door 2, revealing a goat behind it”, not the host will never open a door that has car behind it. If the host always open door 2, regardless of what is behind it, then the probability will be the same, as the sample[1] == 1 case will not increment the wins, and $P(E)$ became a independent event that has a chance of 1.

///

You can find more about the problem on wikipedia.