Thursday, April 2, 2009

Monty Hall problem, a logic seems against the common sense

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, 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?

I have encountered this question in IQ test at facebook and I answered as "it doesn't make a difference to switch or not as i would have a 50% probability to win". I was surprised when i was told that i'm wrong, then i discovered that is a big argument for a problem presented by the game show "Let's make a deal"

i have read explanations about it but without much concentration, i was not convinced anyway, so i wrote a simple quick and dirty simulation in php which results around 66% probability to win, then i had to take a deep breath and said "Well, let's really think"

This is my sim code written in php

<?
function prove_montyhall_or_break_it(){
srand((float) microtime() * 10000000);
$doors = array(1=>"G", 2=>"G", 3=>"G");
$num = array(1,2,3);
$x = array_rand($num)+1;
//setting car's door
$doors[$x]='C';

//Think of one door
$y = array_rand($num)+1;
$original_choice=$doors[$y];
unset ($doors[$y]);

//find the goat door and remove it so the remaining door will be the one that you will to switch to if u want

$goatdoorkey = array_search('G', $doors);
unset ($doors[$goatdoorkey]);


if (in_array("C", $doors)) {
return true;
}else{
return false;
}
}
$trials= 1000000;
$wins=0;
$losses=0;

for ($i = 0; $i < $trials; ++$i) { if (prove_montyhall_or_break_it()){ ++$wins; }else{ ++$losses; } } echo "out of $trials trial: <br > wins are $wins <br > losses are $losses"; ?>


After a while of thinking i found it simple. It is the same thing like selecting two doors from three, and the host will open the door which has the goat behind out of these two. Selecting two will give probability of 2/3 to win , removing the non winner door out of the selected two will not affect your probability to win. So switching in the original game equals to choosing two doors.

C for car and G for Goat

Door A > G
Door B > G
Door C > C

Selecting "door A" will enforce the host to open "B" > switching wins
Selecting "door B" will enforce the host to open "A" > switching wins
Selecting "door C" will make the host to open either "A" or "B" > switching fails

Switching will give you 2 chances to win out of 3. this happens only if the host knows where is the car. If the host doesn't know, your probability to win will be 1/2. So you will always have to switch unless you want to win a goat.

1 comment:

jane said...

i never knew that i was playing hide and seek with an all rounder.Amy i never knew that i am in love with a guy who is not only a doctor and an engineer but the romio of his julliette at the same time.jane is missing you amy.
I LOVE YOU AHMED