Day 10 - The Monty Hall Problem

THATS WHY HE'S THE 🐐
05 May 2025

In front of you there are three doors. A game show host tells you that behind one of these doors, is everything you could ever dream of. He asks you to pick one, with each door having an equal chance of hiding the prize.

3 Doors

You make your choice.

The host now opens one of the two you didn’t pick. It’s empty. Now he asks:

Do you want to switch to the other unopened door?

You might think it doesn’t matter—after all, there are two doors left, so it feels like a 50-50 chance. But you should always switch.

Why?

When you first made your choice, the chance of picking the prize was one in three. That means the prize was more likely to be behind one of the other two doors. But he never opens the door with the prize. He always shows you an empty one.

Chosen Door

So now the odds are shifted to the unopened door, while your original pick maintains its probability of a third. Therefore, switching the door would give you a better chance of winning.

This question originated from a game show called Let’s Make a Deal, hosted by Monty Hall, hence the problem is named after him.

Still don’t believe it? I didn’t as well. Turns out famous mathematician Paul Erdös didn’t too. I guess we are all on the same level. But here’s some code in python that proves that the odds of winning approximate to 2/3.

import random

def simulate_monty_hall(trials=10000):
    stay_wins, switch_wins = 0, 0
    doors = [1, 2, 3]

    for _ in range(trials):
        prize = random.choice(doors)
        choice = random.choice(doors)

        # Host opens a door that is not the prize and not the contestant's choice
        host_opens = random.choice([d for d in doors if d != choice and d != prize])

        # Door left to switch to
        switch_choice = next(d for d in doors if d != choice and d != host_opens)

        # Check outcomes
        if choice == prize:
            stay_wins += 1
        else:
            switch_wins += 1

    print(f"Staying wins: {stay_wins}")
    print(f"Switching wins: {switch_wins}")
    print(f"Winning percentage when switching: {switch_wins / trials * 100:.2f}%")
    print(f"Winning percentage when staying: {stay_wins / trials * 100:.2f}%")

simulate_monty_hall()