Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 204926

Submitted on 17 Feb 2013 by Khaled Hamed

Correct

24Size
Leading solution size is 12.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
win=0;
Pass=0;
for i=1:100
 prize=randi(3);
 doors=[0 0 0];
 pick=Monty(doors);
 pick=floor(pick);
 if pick<1 || pick>3
  win=0;
  break;
 else
  doors(pick)=1;
 end
 if pick==prize
 % Random select from other doors
  if rand>0.5
   doors(find(doors==0,1))=2;
  else
   doors(find(doors==0,1,'last'))=2;
  end
 else %
 % Pick other and not prize door
  reveal=setxor(prize,setxor(pick,[1 2 3]));
  doors(reveal)=2;
 end
 pick=Monty(doors);
 pick=floor(pick);
 if pick==prize
  win=win+1;
 end
end % Monty Loops
win % Display number of wins
if win>50,Pass=1;end
assert(isequal(Pass,1))
win =
    65