Chapter 2: two-stage simulation for n-card, m-queen monty hall
Chapter 2: two-stage simulation for n-card, m-queen monty hall
For the modified Monty Hall problem described above, there are two stages. In the first stage of our simulation we will generate a large set of pseudorandom orders of numbers between 1 and 5, and use the first two from each order to indicate which cards contain Queens. The second stage involves removing one of the non-Queen cards, and determining whether a Queen would have been found by our simulated ‘contestant’ by switching. The logic of the simulation is that at completion we can simply count the number of winning simulation runs when the contestant switches versus the wins from staying.
REPS=100000;
Ncards=5; Nqueens=2;
D=1:Ncards; %define the ‘deck’ of cards
C=[0 0]; %initialize counter vector
for n=1:REPS,
Pick1=randi(Ncards); %End of stage 1
Dnow=find(D~=Pick1); %Remove chosen card from list
ind=randi(Ncards-2); %Select new card
Pick2=Dnow(ind(1));
C(1)=C(1)+any(Pick1==[1 Nqueens]); %Stay wins
C(2)=C(2)+any(Pick2==[1 Nqueens]); end %Switch wins
C/REPS