Monty Hall Simulation

Mo Abdelhady profile picture

Mo A. Abdelhady

August 21, 2022

Understanding the Monty Hall Problem

The Monty Hall problem is a famous illustration of probability, often counterintuitive to our logical instincts.

Simulator

Check out the simple simulator here

The Scenario

Imagine you're on a game show choosing from three doors: behind one is a car, behind the others, goats. You pick a door, say No.1, and the host, who knows what's behind the doors, opens another door, say No. 3, revealing a goat. He then gives you a chance to switch your choice to door No. 2. What would you do?

The Math Behind the Decision

Mathematically, switching doors boosts your chances of winning the car from 1/3 to 2/3. Here's why:

  • Initial Choice: 1/3 chance the car is behind your chosen door, 2/3 chance it's behind one of the others.
  • Reveal: The host always reveals a goat from the remaining doors.
  • Switch: By switching, you take advantage of the initial 2/3 probability.

Simulation Setup

Let's validate this by simulating the game multiple times. Here's how the game is set up:

import numpy as np

def setup_game():
    # Initialize a game with one car and two goats randomly placed behind three doors
    prizes = np.array(["goat", "goat", "car"])
    doors = [1, 2, 3]
    np.random.shuffle(prizes)
    np.random.shuffle(doors)
    game = {door: prize for door, prize in zip(doors, prizes)}
    return game, doors

Running the Simulation

We simulate choosing doors with both 'stay' and 'switch' strategies and record the win rates:

def run_simulation(n_trials, strategy):
    wins = sum(play(strategy) for _ in range(n_trials))
    print(f"Strategy: {strategy}, Win Rate: {wins / n_trials:.4f}")

run_simulation(10000, "stay")
run_simulation(10000, "switch")

Results and Conclusion

The empirical results closely match our mathematical expectations:

  • Stay: About 32.5% win rate
  • Switch: About 66.1% win rate

These results empirically affirm the mathematical advantage of switching doors on the Monty Hall game show. Always trust the math over intuition!