# Prove the Monty Hall Problem (via Simulation)!

• (4 Pages)
• « First
• 2
• 3
• 4

## 57 Replies - 12914 Views - Last Post: 03 October 2013 - 09:30 PM

### #46 lucky3

• Friend lucky3 As IHelpable

Reputation: 231
• Posts: 761
• Joined: 19-October 11

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

Posted 11 July 2013 - 11:58 AM

I thought players chances would go up to 99% if facing 100 door to choose and change his/her mind (or is there something wrong with the code, or my thinking about the problem?).
Spoiler

### #47 jon.kiparsky

• Pancakes!

Reputation: 7132
• Posts: 11,793
• Joined: 19-March 11

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

Posted 11 July 2013 - 12:17 PM

lucky3, on 11 July 2013 - 01:58 PM, said:

I thought players chances would go up to 99% if facing 100 door to choose and change his/her mind (or is there something wrong with the code, or my thinking about the problem?).

That's correct. You have 1/100 chance of getting the door right the first time. That means 99/100 chance of getting it wrong. So when they open 98 doors, the second choice is, "did you get it right the first time?" The odds of that being "no" are still 99%.

In all cases, the odds of the prize being behind the "switch" door are 1-1/n: the odds that the prize is behind some door are 1/1, and the odds that you picked that door are 1/n. Therefore the odds that it's behind some other door are 1-1/n, and there's only one other door for it to be behind.

### #48 PalmeN

Reputation: 1
• Posts: 1
• Joined: 25-August 13

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

Posted 25 August 2013 - 04:47 AM

I was actually really amazed when i found the answer, i understood the explaining on different sites with the 2/3 to win 1/3 to lose etc, but still it felt wrong, because when you have 2 doors left it shouldn't matter what you choose, it should always be 50%, so i made a little program and simulated it. Really cool actually, here are my results + code:

Results:

Wins: 6664927
Losses: 3335073
After 10000000 Turns
66% to win
33% to lose
10000000 Simulations executed in 40899,325 Milliseconds

Code:

```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Diagnostics;

{
/// <summary>
/// Interaction logic for Mainwindow.xaml
/// </summary>
public partial class MainWindow : Window
{

ulong wins = 0;
ulong losses = 0;

Random ra = new Random();

Door door1, door2, door3;

double winPercent;
double lossPercent;

public MainWindow()
{
InitializeComponent();

door1 = new Door();
door2 = new Door();
door3 = new Door();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
ulong n = Convert.ToUInt64(textBox1.Text);

Stopwatch timer = new Stopwatch();
timer.Start();

for (ulong i = 0; i < n; i++)
{

Random r = new Random(ra.Next(9852354));

door1.isChosen = false;
door2.isChosen = false;
door3.isChosen = false;
door1.isCar = false;
door2.isCar = false;
door3.isCar = false;
door1.isRemoved = false;
door2.isRemoved = false;
door3.isRemoved = false;

int chosenDoor = r.Next(1, 4);
int isCar = r.Next(1, 4);

switch (chosenDoor)
{
case 1:
door1.isChosen = true;
break;
case 2:
door2.isChosen = true;
break;
case 3:
door3.isChosen = true;
break;
}

switch (isCar)
{
case 1:
door1.isCar = true;
break;
case 2:
door2.isCar = true;
break;
case 3:
door3.isCar = true;
break;
}

if (!door1.isChosen && !door1.isCar)
door1.isRemoved = true;
else if (!door2.isChosen && !door2.isCar)
door2.isRemoved = true;
else if (!door3.isChosen && !door3.isCar)
door3.isRemoved = true;

if (!door1.isRemoved && !door1.isChosen)
{
if (door1.isCar)
wins++;
else
losses++;
}
if (!door2.isRemoved && !door2.isChosen)
{
if (door2.isCar)
wins++;
else
losses++;
}
if (!door3.isRemoved && !door3.isChosen)
{
if (door3.isCar)
wins++;
else
losses++;
}

/*if (door1.isChosen)
if (door1.isCar)
wins++;
else
losses++;
if (door2.isChosen)
if (door2.isCar)
wins++;
else losses++;
if(door3.isChosen)
if(door3.isCar)
wins++;
else
losses++;*/
}
timer.Stop();

winPercent = (wins * 100) / n;
lossPercent = (losses * 100) / n;

textBox2.Text += "Wins: " + wins.ToString() + "\nLosses: " + losses.ToString() + "\nAfter " + n.ToString() + " Turns\n" + winPercent.ToString() + "% to win\n" + lossPercent.ToString() + "% to lose\n" + n.ToString() + " Simulations executed in " + timer.Elapsed.TotalMilliseconds + " Milliseconds";
}

}
}

```

The commented part is if you want it not to switch door.
I also made a program with a progress bar for the simulation, however it takes like 10times longer (since it has to switch threads etc) so it's not worth using it.

### #49 Robin19

Reputation: 256
• Posts: 529
• Joined: 07-July 10

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

Posted 02 October 2013 - 09:35 AM

Momerath, on 22 September 2012 - 01:26 PM, said:

And this problem is why I can no longer watch Deal Or No Deal. They consistently misstate the odds of having the \$1,000,000 case, and I yell at the TV. My wife doesn't like it when I yell at the TV />/>

And if you are ever on the show and you are down to the last two cases and they ask if you want to switch your case, you say YES!

The Monty Hall problem has a caveat: the host knows which of the remaining doors is no good.

With Deal or No Deal, the contestant is the one that chooses which cases are opened. The location of the \$1M is not 24/25 in the other case. I think that if you get down to 2 cases, the odds are 50/50.

Now we know what the next simulation challenge will be.

This post has been edited by Robin19: 02 October 2013 - 09:36 AM

### #50 modi123_1

• Suitor #2

Reputation: 8150
• Posts: 29,981
• Joined: 12-June 08

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

Posted 02 October 2013 - 10:19 AM

FYI - using MS HPC (high performance computing) you can setup a cluster of client machines to crunch Monty Hall simulations through a plugin for Excel. I saw a demo (a while back) of a guy with a 20-ish CPU cluster set up with HPC and the front end being ran by Excel. Nifty fo'sho'.

http://msdn.microsof...y/cc983823.aspx
https://www.microsof...us/default.aspx

### #51 Momerath

• D.I.C Lover

Reputation: 944
• Posts: 2,259
• Joined: 04-October 09

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

Posted 02 October 2013 - 12:49 PM

Robin19, on 02 October 2013 - 09:35 AM, said:

The Monty Hall problem has a caveat: the host knows which of the remaining doors is no good.

With Deal or No Deal, the contestant is the one that chooses which cases are opened. The location of the \$1M is not 24/25 in the other case. I think that if you get down to 2 cases, the odds are 50/50.

Now we know what the next simulation challenge will be.

Doesn't make a difference. Chance you chose the correct case initially is 1 in 25. That never changes.

Even in the MH problem, if the host let you choose one of the door to open and it didn't have the prize, do you think that changes the odds? In other words, it doesn't matter who makes the choice for which door to open, as long as the door opened (case opened, whatever) doesn't have the top prize.

The only reason they include that in the MH problem is so that the host can guarantee that the top prize isn't revealed.

Now to add more complication. Let's say another player is added to the game after the first door is opened. What are his/her odds of picking the right door if
a) they don't know what door you chose
b) they know what door you chose

This post has been edited by Momerath: 02 October 2013 - 12:53 PM

### #52 Robin19

Reputation: 256
• Posts: 529
• Joined: 07-July 10

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

Posted 03 October 2013 - 09:16 AM

It does make a difference. Monty Hall would always pick the winning door if you picked a losing door. The last case in Deal or No Deal is picked by the player, so it has just as much a chance to be the winner as the 1st case they picked.

3 prizes
Player picks 1 out of 3 remaining. 1/3 chance he has the winner.

Let's Make a Deal:
Mr. Hall picks 1 out of 2 remaining. If he picked a loser, he will then choose the other prize. 2/3 chance he is offering to switch a winner. Let's Make a Deal garantees that the prize thrown away is a loser.

Deal or No Deal:
Player picks 1 out of 2 remaining to throw away. 1/3 chance the last case to switch is the winner. Because Deal or No Deal has a (x - 2) / x chance of having an outcome that is impossible in Let's Make a Deal.

I modified my overly complicated Monty Hall solution to play Deal Or No Deal. This returns a 9992/9905 split in favor of keeping the case (with the supplied seed of 2). Some seed numbers generate a higher rate for switching, but it is always statistically a 50/50 split. This code throws out any result in which a player reveals the prize before they get to the last game since that is not what we are testing. That is where the extra percentages that the Hall problem has that is not present in Deal or No Deal.
Spoiler

This post has been edited by Robin19: 03 October 2013 - 11:36 AM

### #53 Robin19

Reputation: 256
• Posts: 529
• Joined: 07-July 10

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

Posted 03 October 2013 - 11:52 AM

Aha, found someone smarter than me that explains it! Deal or No Deal is a Monty Fall problem. 50/50 on whether you should switch cases.

### #54 jon.kiparsky

• Pancakes!

Reputation: 7132
• Posts: 11,793
• Joined: 19-March 11

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

Posted 03 October 2013 - 11:58 AM

For those of us who don't watch American television shows, could someone please state the conditions of the "Deal Or No Deal" variant?

### #55 Momerath

• D.I.C Lover

Reputation: 944
• Posts: 2,259
• Joined: 04-October 09

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

Posted 03 October 2013 - 02:57 PM

There are 25 cases with various amounts of money, from \$0.01 to \$1,000,000. You are given a choice of 1 case. Then the hosts ask the contestant to pick some cases to open. After some cases are opened, the contestant is offered some amount of money to quit the game based on the values revealed. This repeats until there are two cases (the one they picked and the other one) at which time the host offers to let them switch cases. There case is opened and they get whatever amount is in it.

And dammit, I hate being wrong. Wrote my own simulation and tested it. Now you've made me have to do math to figure out why

### #56 jon.kiparsky

• Pancakes!

Reputation: 7132
• Posts: 11,793
• Joined: 19-March 11

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

Posted 03 October 2013 - 03:23 PM

I assume that I do not have the choice of taking any of the unopened boxes (since then my strategy is just to open boxes until the million is revealed, which will happen with probability 23/25. So once a box is opened, it's gone.

Do I know anything about the distribution of prizes? I assume that there is guaranteed to be a million, and at least on one-cent box. What you haven't told me is whether I know what prizes are in the boxes to be found.

Assume that I know something about the distribution, and I proceed to open boxes until there are two. In fact, assume I know exactly what the distribution is.

At this point, I know exactly what is in the two boxes (by elimination) and I know that there are two ways those items can be distributed, and I know that the odds of either distribution are equal. So if I get down to the last option, assuming I know what prizes were there to be distributed in the first place, I have no basis to decide between the two.

This is NOT the Monty Hall problem because in the Monty Nall problem there is exactly one desirable prize, and the booby prizes are homogenous. So in Monty, we have a 1/n chance of getting it right the first time, and therefore a n-1/n chance of having got it wrong. Here we're looking at something quite different. We have a 1/n chance of hitting the top prize the first time, true enough, but that's not the issue. The decision at the end is between two known values, either of which could have been our first choice with equal likelihood.

So if you run the simulation to the end with "switch" and "stay" as your two conditions, I predict equal outcomes over time. I think this would be equally true if you set up a deviant case with one million-dollar box and 24 one-cent boxes.

On the other hand, there may be some interesting analysis of expectation for the interim questions. I suspect there may be points in the game where it is advantageous to take the buyout, but I'd have to have a lot more information about the setup before I could think about working that out.

This post has been edited by jon.kiparsky: 03 October 2013 - 03:23 PM

### #57 NantucketSleighride

Reputation: 21
• Posts: 104
• Joined: 13-February 11

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

Posted 03 October 2013 - 06:55 PM

I'm pretty late to this - but I thought it was a neat idea. I just made up some messy code to give it a go... But I left some stuff out; I only roll once for each attempt, because there doesn't seem to be any point on switching guesses... Either you got it right, or you didn't. The data will be the same whether you write more code to change the guess and store the results, or not.

After running it many times with various numbers - I really do seem to get about 33% or so each time; showing me that switching is quite obviously the advantageous move. And it makes perfect sense that it is, after doing some reading of this thread (before it, I was skeptical).

I just wrote it up quickly, so it's sloppy:

```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Random rnd = new Random();
int correctGuesses = 0;
int incorrectGuesses = 0;

Console.Write("How Many Times To Run Simulation? > ");
int repeat = int.Parse(input);

for (int x = 0; x < repeat; x++)
{

int number = rnd.Next(1, 4);
int guess = rnd.Next(1, 4);

if (number == guess)
{
correctGuesses++;
}
else
{
incorrectGuesses++;
}

}

Console.WriteLine("Correct Guesses: {0}", correctGuesses);
Console.WriteLine("Incorrect Guesses: {0}", incorrectGuesses);
Console.WriteLine("Program Ended...");

}
}
}

```

### #58 Momerath

• D.I.C Lover

Reputation: 944
• Posts: 2,259
• Joined: 04-October 09

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

Posted 03 October 2013 - 09:30 PM

jon.kiparsky, on 03 October 2013 - 03:23 PM, said:

Do I know anything about the distribution of prizes? I assume that there is guaranteed to be a million, and at least on one-cent box. What you haven't told me is whether I know what prizes are in the boxes to be found.

First, I was in error, there are 26 boxes to start. And yes, you know all the values, they are:
\$.01, \$1, \$5, \$10, \$25, \$50, \$75, \$100, \$200, \$300, \$400, \$500, \$750, \$1,000, \$5,000, \$10,000, \$25,000, \$50,000, \$75,000, \$100,000, \$200,000, \$300,000, \$400,000, \$500,000, \$750,000, \$1,000,000

I also found this web page