# Prove the Monty Hall Problem (via Simulation)!

• (5 Pages)
• 1
• 2
• 3
• Last »

## 61 Replies - 29834 Views - Last Post: 03 March 2015 - 10:27 AM

### #1 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5102
• Posts: 9,283
• Joined: 08-June 10

# Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 12:45 PM

Quote

Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1 [but the door is not opened], and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?

Spoiler

Some of you yourselves may not believe the predicted result.

Here's the interesting bit from the article:

Quote

Many readers refused to believe...After the Monty Hall problem appeared in Parade, approximately 10,000 readers, including nearly 1,000 with PhDs, wrote to the magazine claiming that vos Savant was wrong (Tierney 1991). Even when given explanations, simulations, and formal mathematical proofs, many people still do not accept...the best strategy. According to the French magazine Le Figaro Magazine, Paul Erdős, the most prolifically published mathematician of modern times, found it very hard to believe the result of his own calculations, and admitted he was not fully convinced until a simple computer simulation confirmed the predicted result.

So, let's write our own simulations and prove or disprove this! Your program can be as simple or complex as you feel necessary, as long as it proves your theory. It must incorporate these key points:

• There are three prizes, one good and two bad.
• After one prize is chosen by the player (at random, without knowing what they have), one bad prize is removed from the left-over choices.
• This is where the simulations must diverge. You must show what happens when the contestant keeps the prize they've already chosen, and what happens when they switch.
• Repetition is key. Small sample runs prove nothing. Write your program so that it proves your hypothesis, or at least strongly suggests it with data.

This is posted in the C# section, but I welcome any language submission.

Edit for clarity: our goal here is to actually write a program to perform the simulation. I know that this is a simple problem to prove with math, but the fun is in writing the code to prove that. I've updated the title to make this more clear.

Is This A Good Question/Topic? 3

## Replies To: Prove the Monty Hall Problem (via Simulation)!

### #2 jon.kiparsky

• Beginner

Reputation: 11018
• Posts: 18,804
• Joined: 19-March 11

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 12:56 PM

The proof has already been provided.

To look at it another way, imagine that there are 100 doors. Now, after you pick one, the host opens 98 doors, leaving one closed. What are the odds that you picked the right door the first time? 1/100. Therefore, what are the odds that the prize is behind the remaining closed door? 99/100.

The same logic holds when N = 3.

Another way to convince yourself is to imagine that you get to select two doors of four - if you have a winner, you keep it. Now the host opens one door each from the selected and the unselected doors. Does switching help you in this case?

The challenge, if you want to be particular about it, is not to prove, but to illustrate the provided proof.

This post has been edited by jon.kiparsky: 19 September 2012 - 01:02 PM

### #3 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5102
• Posts: 9,283
• Joined: 08-June 10

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 12:59 PM

Completely true. I suppose I should have made it more clear that this is a programming exercise to prove what math can and has already proven with an actual simulation.

### #4 jon.kiparsky

• Beginner

Reputation: 11018
• Posts: 18,804
• Joined: 19-March 11

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 01:03 PM

Just me being nitpicky, don't mind me. Expect a scala solution this evening, since that's what I'm learning now.

### #5 modi123_1

• Suitor #2

Reputation: 13947
• Posts: 55,683
• Joined: 12-June 08

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 01:08 PM

Heh.. I was going to post a link to Mythbusters and declare myself done. Now I gotta write up some code that links to, and plays, the mythbusters video to win!

### #6 jon.kiparsky

• Beginner

Reputation: 11018
• Posts: 18,804
• Joined: 19-March 11

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 01:12 PM

I'm going to deliver actual goats and cars to the user. You're going to have to beat that, buddy.

### #7 modi123_1

• Suitor #2

Reputation: 13947
• Posts: 55,683
• Joined: 12-June 08

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 01:21 PM

Pffssh.. what evs..

Who would want your Bostonian sourced gutter goats anyways with their broad-a bleats and reeking of Belichick's musk?

I, on the other hand, have organically grown petite lap goats that also dress up in AT-AT costumes, bleat with an accent neutral voice of an angel, and are hypoallergenic.

### #8 CodeGrappler

Reputation: 41
• Posts: 120
• Joined: 29-November 10

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 01:32 PM

modi123_1, on 19 September 2012 - 01:21 PM, said:

Pffssh.. what evs..

Who would want your Bostonian sourced gutter goats anyways with their broad-a bleats and reeking of Belichick's musk?

I, on the other hand, have organically grown petite lap goats that also dress up in AT-AT costumes, bleat with an accent neutral voice of an angel, and are hypoallergenic.

But you don't have cars...

### #9 modi123_1

• Suitor #2

Reputation: 13947
• Posts: 55,683
• Joined: 12-June 08

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 01:39 PM

My petite lap goats believe in being green - that's why some dress up as AT-ATs - as a simulation of a car without the unneeded carbon foot print.

### #10 jon.kiparsky

• Beginner

Reputation: 11018
• Posts: 18,804
• Joined: 19-March 11

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 01:52 PM

Not much meat on one of them petite lap coats, is there?

### #11 CTphpnwb

• D.I.C Lover

Reputation: 3777
• Posts: 13,674
• Joined: 08-August 08

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 02:27 PM

Too soon?
Spoiler

This post has been edited by CTphpnwb: 19 September 2012 - 02:29 PM

### #12 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5102
• Posts: 9,283
• Joined: 08-June 10

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 02:47 PM

Definitely not too soon.

Here was my solution:

Spoiler

### #13 baavgai

• Dreaming Coder

Reputation: 7150
• Posts: 14,890
• Joined: 16-October 07

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 05:14 PM

Sorry, been working in Python all day.
Spoiler

Wondering if any clever LINQ person could make that happen in C#, since it looks rather LINQy.

### #14 jon.kiparsky

• Beginner

Reputation: 11018
• Posts: 18,804
• Joined: 19-March 11

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 19 September 2012 - 11:50 PM

Here's a pretty straightforward python implementation. Too tired to try to do it in scala tonight.

Spoiler

EDIT: Due to technical difficulties, this version does not deliver goats and cars. However, if my kickstarter comes through I'll be developing my e-goat delivery system and that little glitch will be addressed.

This post has been edited by jon.kiparsky: 20 September 2012 - 11:54 AM

### #15 fromTheSprawl

• Bloodborne

Reputation: 522
• Posts: 2,102
• Joined: 28-December 10

## Re: Prove the Monty Hall Problem (via Simulation)!

Posted 20 September 2012 - 01:24 AM

I'm not sure if what I did is correct, but here's something from Python:

Spoiler

100 runs
Spoiler

1000 runs
Spoiler

A million ways
Spoiler

Yeah I know, the code needs improvement lots. I hope one day I can do something like baavgai's on Python.
From the figures, yeah I think the Monty Hall problem proves itself... unless if what I did is completely off. There there.