# MATLAB Simulation of the Monty Hall Problem

### The Game

*Two goats and one car are hidden behind three doors. You pick a door, but before revealing what's behind the door you chose, the game host opens another door where a goat is hidden. The question: should you switch your choice of door?*

I heard about the Monty Hall problem in my first undergraduate probability course. Five years later when I did another probability course in grad school I was told again that the correct response is to always switch.

"No way!"

The result is utterly counter-intuitive, so I wrote a MATLAB script to simulate the problem. It compares the two strategies: one always switches, and the other, never. Just execute montyhall.m to compare the frequency of winning (scripts at bottom of page).

Surprisingly (perhaps not to the Mathematicians) switching **does** increase the chance of getting the car, so much in fact it actually doubles your chance of winning from 1/3 to 2/3 - exactly as the theory has predicted.

That means if someone walks in after the host has revealed one goat and is asked to pick one of the two doors, that new person has 1/2 chance of getting the car while it remains 1/3 to me if I don't change my mind. But it is the same set of objects at the same moment of time!

The claim is that if the host knows where the car is hidden, his act of opening a door with goat actually increases the probability of the *remaining* door hiding the car. If I have time I will write another simulation where the game host *doesn't* know where the car is - I was told in this case your probability of winning would remain unchanged at 1/3. We will see about that.

**Thoughts**

What if I want the *goat* instead? What's P(got a goat)?