I made a simulation in MATLAB that showed that if you stay, you win 37.5% of the time and that if you switch, you win 63.5% of the time. This was done ten times over iterations of 500,000 times (so 5 million times each).
I have always been told that the probability of STAYING should be 1/3 and the probability of SWITCHING should be either 2/3 or 1/2 (depending on whom you ask). What is going on here?
If you'd like to see the code or anything, please let me know.
CODE:
clear
%STAY option
max = 500000; % number of games played
win = 0; % win counter
n = 0; % index counter
while n < max
game = round(rand(1)*2)+1; % generate prize door
player = round(rand(1)*2)+1; % player selects door
if (player~=game)
n=n+1;
else
win = win+1;
n=n+1;
end
end
display("Wins if STAY:")
win
display("Games played on STAY:")
n
display("Percentage won on STAY option:")
win/n*100
%SWITCH option`
max = 500000; % number of games played
win = 0; % win counter
n = 0; % index counter
while n < max
game = round(rand(1)*2)+1; % generate prize door
player = round(rand(1)*2)+1; % player selects door
if (player~=game)
win = win+1;
n=n+1;
else
% win = win+1;
n=n+1;
end
end
display("Wins if SWITCH:")
win
display("Games played on SWITCH:")
n
round(3*rand(1)+1/2)
orfloor(3*rand(1))+1
– robjohn Jul 07 '15 at 21:00randi([1,3])
to generate a uniformly random integer between (and including) 1 and 3. – Eff Jul 07 '15 at 21:11