Perl scripts that proves the 3 door problem...

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
I forgot I still had this... This program is an experiment for the 3 doors problem. Here is the problem :

Behind a door there is a prize.
You select a door.
The host opens a door that does not have the prize behind it and asks if you would like to change your choice to the other door.
Should you switch? Does it make a difference?


#!/usr/bin/perl -w

srand($$|time);

$matches = '0';
@Set = qw(1 2 3);
$count = '1000000';
populate();

for ($i=0;$i<$count;$i++) {
$temp = int(rand($#Set+1));
$guess = $Set[$temp];
if ($Test[$i] == $guess) {
$matches++;
}
}
print("Trial 1 successes = $matches\n");

# Populate Test array for 2nd test
populate();
$matches = '0';

for ($i=0;$i<$count;$i++) {
$temp = int(rand(@Set));
$guess = $Set[$temp];
$matches += opendoor();
}

print("Trial 2 successes = $matches\n");

sub populate {
for ($i=0;$i<$count;$i++) {
$temp = int(rand($#Set+1));
$Test[$i] = $Set[$temp];
# print("$Test[$i]");
}
}

sub opendoor {
# Cases where guesser chose right on the first try means he will lose
# if switches doors.
if ($guess == $Test[$i]) {return 0;} else {return 1;}
}

Hopefully it doesn't look too horrible... the forums never keep the formatting...
 

Supermercado

Diamond Member
Jan 18, 2002
5,893
0
76
Oh, this problem... This was a bonus on one of my computer science tests last year. I've never been able to understand why you change your choice :eek:
 

Beattie

Golden Member
Sep 6, 2001
1,774
0
0
when you pick a door, you have a 1/3 chance of being right. After opening a door, there are 2 left, and therefore, you have a 1/2 chance of being right. If you stay at the same door, the probability is still 1/3 since it is what you selected the first time. Therefore, changing doors increases your chance of winning from 1/3 to 1/2.

I believe that is the correct reasoning behind it.
 

Zenmervolt

Elite member
Oct 22, 2000
24,514
43
91
Originally posted by: Beattie
when you pick a door, you have a 1/3 chance of being right. After opening a door, there are 2 left, and therefore, you have a 1/2 chance of being right. If you stay at the same door, the probability is still 1/3 since it is what you selected the first time. Therefore, changing doors increases your chance of winning from 1/3 to 1/2.

I believe that is the correct reasoning behind it.
Actually, it switches your chances from 1/3 to 2/3. When you chose the first door, there is a 2/3 chance that the prize is not behind that door. When one of the prizeless doors is opened, there remains the 2/3 chance that the prize is not behind the door you chose at first, and since there is 0 chance that the prize is behind the open door, the 2/3 chance is all embodied by the door you did not choose. So if you switch, you will be right 66.66% of the time over the long run. (Man I loved Statistics class.)

ZV
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
I like it better like this :):

#!perl-w

usestrict;

my$matches=0;
my@Set=(1,2,3);
my$count=1000000;
my@Test=&populate;

for(my$i=0;$i<$count;$i++){
my$temp=int(rand(@Set));
my$guess=$Set[$temp];
if($Test[$i]==$guess){
$matches++;
}
}
print"Trial1successes=$matches\n";

#PopulateTestarrayfor2ndtest
@Test=&populate;
$matches=0;

for(my$i=0;$i<$count;$i++){
my$temp=int(rand(@Set));
my$guess=$Set[$temp];
$matches+=opendoor($guess,$i);
}

print"Trial2successes=$matches\n";

subpopulate{
my@Test;
for(my$i=0;$i<$count;$i++){
my$temp=int(rand($#Set+1));
$Test[$i]=$Set[$temp];
}
return@Test;
}

subopendoor{
if($_[0]==$Test[$_[1]]){return0}
else{return1}
}
 

HappyFace

Diamond Member
Nov 2, 1999
6,265
5
81
Um is it just me or is the answer totally obvious!? Choosing another door gives you one more chance at winning, while staying with the same door guarantees that you'll get NOTHING.
 

Zenmervolt

Elite member
Oct 22, 2000
24,514
43
91
Originally posted by: HappyFace
Um is it just me or is the answer totally obvious!? Choosing another door gives you one more chance at winning, while staying with the same door guarantees that you'll get NOTHING.
Staying with the same door doesn't guarantee nothing. It's still a 1/3 chance. The prizeless door the host opens is not the same door you chose.

ZV
 

klah

Diamond Member
Aug 13, 2002
7,070
1
0
You are leaving out a few of the assumptions, namely the behavior and motives of the host. I believe this problem came to notoriety when Marilyn Savant addressed the matter a few years ago.
 

BoberFett

Lifer
Oct 9, 1999
37,562
9
81
Remember, there's lies, damn lies, and statistics.

Somebody could use statistics to convince you to choose the door that was already opened.
 

MichaelD

Lifer
Jan 16, 2001
31,528
3
76
There is no spoon behind door two.

This thread is so above my head, I couldn't reach it with a step ladder. I'll sit here and watch the smart people argue. *pops open can of beer*
 

Zenmervolt

Elite member
Oct 22, 2000
24,514
43
91
Originally posted by: BoberFett
Remember, there's lies, damn lies, and statistics.

Somebody could use statistics to convince you to choose the door that was already opened.
That's why I love statistics. With any given set of numbers and a little time and effort, one can "prove" two contradictory assumptions. :) It's amazing how handy that ability comes in for a business/Finance major. ;)

ZV
 

FenrisUlf

Senior member
Nov 28, 2001
325
0
0
The act of giving you the chance to change your choice causes this to be a choice between 2 items, not 3. Revealing one item and giving a second chance to choose changes the statistical problem. You already know that one is NOT the correct choice, so you get one pick from two items. The third item becomes moot. This is assuming that this is truly a non-biased, statistically accurate thing.
 

Zenmervolt

Elite member
Oct 22, 2000
24,514
43
91
Originally posted by: FenrisUlf
The act of giving you the chance to change your choice causes this to be a choice between 2 items, not 3. Revealing one item and giving a second chance to choose changes the statistical problem. You already know that one is NOT the correct choice, so you get one pick from two items. The third item becomes moot. This is assuming that this is truly a non-biased, statistically accurate thing.
No, the third choice still exerts an influence. Whichever door you choose only has a 1/3 chance of winning, giving the chance to change your pick does not change the chance to 1/2. The door you chose still has only a 1/3 chance of being the winner even after one of the losing doors is opened. If you disagree with this, take it up with Dr. Carl Bodenschatz who taught me last year.

ZV
 

Kev

Lifer
Dec 17, 2001
16,367
4
81
I'm thinking about it this way....

If you get a second choice between 2 doors, you are basically taking a 50/50 chance that changing your choice would cause you to either get the prize or not get it. So I don't see how changing your choice could possibly enhance your chances at getting the prize.

Another way to think about it: Suppose you choose door 1, and door 3 is revealed to not have the prize. What if you had chosen door 2 initially, what difference would that have made? It would have the same effect as changing your choice.

OK brain, you can rest and go back to neffing now.
 

kranky

Elite Member
Oct 9, 1999
21,019
156
106
This is the way I finally understood why changing your choice is better.

If you pick one door and don't switch, your chance of winning is 1/3.
If you pick one door and let me have the other two doors, MY chance of winning is 2/3.
The guy who switches gets the equivalent of "the other two doors" - one which is proven to be a loser when the host shows one door that doesn't have the prize (since there's only one prize, you already knew one of the two was a loser) and the remaining door, which may or may not win.
 

crystal

Platinum Member
Nov 5, 1999
2,424
0
76
Ok, I get confuse here.

You pick first door. The host opens it, but does he/she tells you what is in that door? Or does he/she just asked, do you want to change your mind and pick another door? (Without telling you what is behind the first door) If that is the case, chances are, you have 1/3 of win on the first time. And 1/3 chance to win on the second time.
 

Zenmervolt

Elite member
Oct 22, 2000
24,514
43
91
Originally posted by: crystal
Ok, I get confuse here.

You pick first door. The host opens it, but does he/she tells you what is in that door? Or does he/she just asked, do you want to change your mind and pick another door? (Without telling you what is behind the first door) If that is the case, chances are, you have 1/3 of win on the first time. And 1/3 chance to win on the second time.
No, the host does _not_ open the door you chose. He opens one of the doors that you did not choose, a door which he knows has nothing behind it.

ZV
 

lebe0024

Golden Member
Dec 6, 2000
1,101
0
76
I absolutely didn't believe this. Until I made a c++ program and ran it a million times for each way. HERES THE RESULTS:

If you automatically stay with your original pick, you have a .33333 chance of winning

If you automatically switch choices, you have a .66666666 chance of winning

If you choose indiscriminately, you have a .500000000 chance of winning. Few people would argue this last one.

Your original door has a 1/3 chance of winning NO MATTER WHAT. THE FACT THAT A LOSER DOOR WAS OPENED MEANS NOTHING! think about it. Also, if you only have to choose between two remaining doors, and you choose randomly, you will win 1/2 the time. SO, the probability of the OTHER door being correct is 2/3 BECAUSE the average of 1/3 and 2/3 is 1/2.

WOW, my brain was fried because of this.
 

lebe0024

Golden Member
Dec 6, 2000
1,101
0
76
If you pick one door and don't switch, your chance of winning is 1/3.
If you pick one door and let me have the other two doors, MY chance of winning is 2/3.
The guy who switches gets the equivalent of "the other two doors" - one which is proven to be a loser when the host shows one door that doesn't have the prize (since there's only one prize, you already knew one of the two was a loser) and the remaining door, which may or may not win.
This is the easist to explain