Friday 20 April 2007

Monty Hall problem

I was thinking about the Monty Hall problem, a problem my statistics teacher once told me about. In short it's about the following:

You appear on a game show. There are three doors, behind one there is a prize. The other two are empty.
Assuming you want to win the prize, you guess which door holds the prize: A,B or C. The gamehost subsequently shows one door behind which the prize doesn't reside. The question is, should you alter your choice or not?

The counterintuitive but correct answer is: Yes.
It's sufficient to look at the two situations: either you alter your choice, or you don't.

If you don't swap:
Two things can happen:
  • You choose a door. You have a chance of 1/3 to choose the right door immediately.
  • Hence you have a chance of 2/3 to choose the wrong door.
Chance of failing: 2/3
Chance of winning: 1/3


If you do swap:
Two things can happen:
  • You choose the door behind which the prize is (chance is 1/3). The gamehost then shows you a door behind which the prize doesn't reside. Two closed doors remain. You change your choice to the other door, so that your final choice will be the wrong one (you fail).
  • You choose a door behind which the prize doesn't reside (chance is 2/3). The gamehost then shows you a door behind which the prize doesn't reside. Again two closed doors remain. You change your choice to the other door, and hence your final choice will be the right one (you win).
Chance of failing: 1/3
Chance of winning: 2/3


You see it's better to change your choice in such a situation.

Small matlab code:
(Note: ceil(3.*rand(1,1)) means that a random number is generated, not higher than 3, rand(1,1) is a random 1x1 matrix).
Sorry for the fucked up code; blogger doesn't like tabs :\.

function findprize=findprize(repeat, swap)

WIN=0;
FAIL=0;
if swap==1;
for i=1:1:repeat
prizenumber=ceil(3.*rand(1,1));
choosenumber=ceil(3.*rand(1,1));

if prizenumber==choosenumber;
FAIL=FAIL+1;
else
WIN=WIN+1;
end
end
end

if swap==0;
for i=1:1:repeat
prizenumber=ceil(3.*rand(1,1));
choosenumber=ceil(3.*rand(1,1));

if prizenumber==choosenumber;
WIN=WIN+1;
else
FAIL=FAIL+1;
end
end
end

FAIL, WIN

This gives:
no swap:
findprize(100000,0) gives: 66625 failures, 33375 wins

swap:
findprize(100000,1) gives: 33438 failures, 66562 wins

There ya go.

1 comment:

Unknown said...

Haha, I'm still clueless >< I guess I'll just go with my trekkie intuition and follow the Vulcan.

Though I'm inclined to choose nice and blue dopey cookie monster :P