Skip to the content.

← Back to Portfolio Hub

Personal Project 3: The Monty Hall Problem — A Probabilistic Paradox

Tip. Every highlighted link in this page is clickable. For fast navagation use Table of Contents

Author: Nels Buhrley Language: Python 3 Visualization: Matplotlib


Snapshot

For a fast technical check, jump to Simulation Design and Results & Visualization.


Table of Contents


Overview

The Monty Hall problem is one of the most famous probability puzzles in mathematics, notorious for contradicting human intuition. This project implements a Monte Carlo simulation to empirically verify the surprising theoretical predictions. Rather than accepting the mathematical result at face value, I built this simulation to visualize the probabilities converging to their theoretical limits — watching 1000 trials reveal the hidden structure of this paradoxical game.

The simulation compares two competing strategies:

The counterintuitive result: switching doubles your probability of winning from 1/3 to 2/3, yet most people instinctively stay.


The Monty Hall Problem

Problem Statement

You are a contestant on a game show. Behind three doors are:

You choose a door. Monty Hall, the host, opens one of the remaining doors to reveal a goat. You now face a choice:

Do you stick with your original choice, or switch to the only other unopened door?

The question asks: which strategy maximizes your probability of winning the car?

The Paradox

The problem gained fame in 1990 when Marilyn vos Savant published her solution in Parade Magazine, claiming that switching is the winning strategy with probability 2/3, while staying wins with probability 1/3. Her column received thousands of letters from readers (including mathematicians and PhDs) insisting she was wrong.

Yet she was right. The paradox arises because human intuition applies flawed probabilistic reasoning — many people believe that after Monty opens a door, the remaining two doors are equally likely to contain the prize (probability 1/2 each). This “symmetry intuition” is incorrect.

Mathematical Analysis

Staying Strategy

Your initial choice has a $\frac{1}{3}$ probability of being correct. Monty cannot change this fundamental fact: he only reveals information about the doors you didn’t choose. Therefore:

\[P(\text{win} \mid \text{stay}) = \frac{1}{3}\]

Switching Strategy

Consider the initial probability partition:

By the law of total probability:

\[P(\text{win} \mid \text{switch}) = P(\text{initially chose goat}) = \frac{2}{3}\]

The key insight: Monty’s action is not random — it’s constrained by the locations of both the car and goats. This constraint reveals information that shifts probability from your door to the remaining door.


Simulation Design

Algorithm

For each trial:

  1. Setup: Randomly place the car behind one of three doors (0, 1, or 2)
  2. Initial Choice: Randomly select your initial door choice
  3. Monty’s Reveal: Monty opens a door that is:
    • Not your chosen door
    • Not the car door
    • (This determines Monty’s choice uniquely when your initial choice contains a goat, but leaves one option when you initially chose the car)
  4. Stay Strategy: Win if your initial choice equals the car door
  5. Switch Strategy: Win if the remaining unopened door (not yours, not Monty’s) contains the car
  6. Record: Track cumulative win rates for both strategies

The simulation runs 1000 trials, computing the empirical win rate after each trial to visualize convergence to the theoretical limits.

Strategies


Results & Visualization

Convergence to Theoretical Probabilities

Monty Hall Convergence Plot

This plot shows the empirical win rate for both strategies across 1000 trials:

The oscillations gradually dampen as the law of large numbers drives both empirical rates toward their theoretical values. By 1000 trials, both strategies have converged visibly close to prediction.

Final Win Rate Comparison

Monty Hall Comparison Bar Chart

After 1000 trials:

The gap between the two strategies is dramatic and consistent — nearly perfect agreement with the theoretical 1/3 vs. 2/3 split.


Running the Simulation

Prerequisites

Execution

python3 code.py

The script runs the simulation and generates two PNG files:


Key Insights

  1. Monty’s constraint is crucial. He cannot open a door randomly — he must avoid both your choice and the car. This asymmetry creates the probability shift.

  2. Intuition fails. Humans tend to interpret Monty’s reveal as creating “new symmetry” (two equal doors, each 1/2). In fact, Monty’s reveal is not symmetric from the game’s perspective; it’s entirely determined by the true locations of cars and goats.

  3. Conditional probability matters. The winning strategy depends on what you want to condition on:
    • Conditional on “you initially chose randomly from three doors,” switching wins 2/3
    • This holds regardless of which specific door Monty actually opens
  4. Empirical verification is powerful. While the math is sound, watching 1000 independent trials converge to the theoretical prediction transforms abstract probability into concrete observation.

Project Structure

Personal Project 3: Monty Hall Simulation (Goat and Car Game Show)/
|-- code.py                           # Main simulation & visualization
|-- monty_hall_convergence.png        # Convergence plot (output)
|-- monty_hall_comparison.png         # Comparison bar chart (output)
`-- README.md                         # This file

References:

← Back to Portfolio Hub