After John W’s skepticism, I decided to put my code where my mouth is — please see:
/portfolio/montyhallsimulator/
It has a simulator, demonstrating the superiority of switching, based on a sample size of 10,000 or less. Source code included. Check it out!
For those of you who remember Let’s Make a Deal the idea of the threedoor choice is very familiar. For those who aren’t familiar with Monty Hall and his extravaganza of gameshowness, here’s the lowdown:
Door 1

Door 2

Door 3

Goat

Goat

New Car

The contestant is presented with a choice of three doors. Two of them have a goat, and one of them has a fabulous prize, like a new car, or a boat, or an evening with Brad Pitt, or whatever. (the contestants were mostly women, since at the time less women were in the workforce, therefore they were the target demographic). Anyways, here’s how it works. They pick one of the doors, then Monty reveals one of the two doors they did not choose; but the door revealed will always contain a goat. The contestant is then allowed to stick with their choice, or change it. The puzzle here is: Is it better odds, statistically speaking, to stick with your choice, or change it, after the goat is revealed? Most mathematicians have said yes in the past, but Marilyn Vos Savant disagreed. Here is a paraphrasing of her proof:
The contestant can pick any one of the three doors, so the odds are 1:3 she will choose correctly. For example, she’ll choose #2. 


Now the host will reveal which one of the doors contains a Goat. It is a certainty he will reveal a goat behind that door, as opposed to accidentally revealing the prize. 


So the odds of Door 1 in this case of being the correct door are 0:3. The odds of your door are 1:3. 


This means that the odds of the remaining door are 2:3 it will be correct. So switching will yield the prize 66% of the time rather than just 33% of the time. 



Scenarios
I’ll now illustrate two different examples of possible outcomes. The left column will be assuming that the contestant always changes their choice when offered, and the right column will be assuming the contestant never changes.
Read each set of data from top to bottom. The sets illustrate the change in gamestate as the game progresses. The lightened boldfaced cell is the selection by the contestant.
Instance 1
Always Switch

 
Never Switch


Door 1

Door 2

Door 3

 
Door 1

Door 2

Door 3


Goat

Car

Goat

 
Goat

Car

Goat


(selected)    (selected)  
Goat

Car

Goat

 
Goat

Car

Goat


(revealed)    (revealed)  
Goat

Car

Goat

   
Goat

Car

Goat


(changed)  (not changed )  
Outcome: Win (changed to Car)  Outcome: Loss (stayed with goat) 
Instance 2
Always Switch

 
Never Switch


Door 1

Door 2

Door 3

 
Door 1

Door 2

Door 3


Goat

Car

Goat

 
Goat

Car

Goat


(selected)    (selected)  
Goat

Car

Goat

 
Goat

Car

Goat


revealed    revealed  
Goat

Car

Goat

   
Goat

Car

Goat


(changed)  (not changed )  
Outcome: Loss (changed to Goat)  Outcome: Win (stayed with car) 
Instance 3
Always Switch

 
Never Switch


Door 1

Door 2

Door 3

 
Door 1

Door 2

Door 3


Goat

Car

Goat

 
Goat

Car

Goat


(selected)    (selected)  
Goat

Car

Goat

 
Goat

Car

Goat


(revealed)    (revealed)  
Goat

Car

Goat

   
Goat

Car

Goat


(changed)  (not changed)  
Outcome: Win (changed to Car)  Outcome: Loss (stayed with goat) 
Do you see the reasoning why changing is always better? Two out of three situations where you change your doorchoice end you up with the car, whereas only 1 in three wins you the car if you don’t change your choice.
Changing your decision effectively inverses the odds into your favor. The fact that the door revealed is not a random door, but rather one of the remaining GOAT DOORS is very important to this; if it weren’t for that, this strategy would not work.
Source Code
<?php $n = isset($_GET['n']) && preg_match("/^\d+$/", $_GET['n']) ? $_GET['n'] : "10"; // Be nice to my host  let's keep the sample sizes relatively small. if ($n > 10000) exit(); /* the_full_monty()  runs through iterations of a monty_hall scenario. argument $switch determines whether it should always switch (true) or never switch (false) */ function the_full_monty($samplesize, $switch = true) { } define('CAR', 1); define('GOAT', 0); class MontyHallSim { private $iterations = 10; // Total private $no_switch_wins = 0; // Number of wins private $switch_wins = 0; private $doors = array(3); private $selection = 0; private $new_selection = 1; private $revealed = 0; public function __construct($iterations){ $this>iterations = $iterations; } public function run() { $this>no_switch_wins = 0; $this>switch_wins = 0; for ($i = 0; $i < $this>iterations; $i++) { $this>doors = array(GOAT, GOAT, GOAT); // Reset doors to all goats $this>doors[rand(0,2)] = CAR; // Replace one of them with a car $this>selection = rand(0,2); // Contestant chooses a door // Reveal one of the goats $this>revealed = 1; do { $this>revealed++; } while ($this>doors[$this>revealed] == 1  $this>revealed == $this>selection); // If set to alwaysswitch, then switch choices. /* The bitwise operator works because: Sel Rev Sum ~Sum 0 (00) 1 (01) 1 (01) 2 (10) 0 (00) 2 (10) 2 (10) 1 (01) 1 (01) 2 (10) 3 (11) 0 (00) */ $this>new_selection = ($this>selection + $this>revealed) ^ 3; if ($this>doors[$this>new_selection] == CAR) { $this>switch_wins++; } if ($this>doors[$this>selection] == CAR) $this>no_switch_wins++; } // endfor } public function graph() { } public function stats() { ?> <div id="data"><ul> <?php echo "<li>Total number of wins where switching helped: " . $this>switch_wins . ", " . 100*($this>switch_wins / $this>iterations) . "%</li>"; echo "<li>Total number of wins where switching hurt: " . $this>no_switch_wins . ", " . 100 * ($this>no_switch_wins / $this>iterations) . "%</li>"; ?> </div> <?php } } ?>