Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
58
Task/100-prisoners/MATLAB/100-prisoners.m
Normal file
58
Task/100-prisoners/MATLAB/100-prisoners.m
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
function [randSuccess,idealSuccess]=prisoners(numP,numG,numT)
|
||||
%numP is the number of prisoners
|
||||
%numG is the number of guesses
|
||||
%numT is the number of trials
|
||||
randSuccess=0;
|
||||
|
||||
%Random
|
||||
for trial=1:numT
|
||||
drawers=randperm(numP);
|
||||
won=1;
|
||||
for i=1:numP
|
||||
correct=0;
|
||||
notopened=drawers;
|
||||
for j=1:numG
|
||||
ind=randi(numel(notopened));
|
||||
m=notopened(ind);
|
||||
if m==i
|
||||
correct=1;
|
||||
break;
|
||||
end
|
||||
notopened(ind)=[];
|
||||
end
|
||||
if correct==0
|
||||
won=0;
|
||||
break;
|
||||
end
|
||||
end
|
||||
randSuccess=randSuccess*(trial-1)/trial+won/trial;
|
||||
end
|
||||
|
||||
|
||||
%Ideal
|
||||
idealSuccess=0;
|
||||
|
||||
for trial=1:numT
|
||||
drawers=randperm(numP);
|
||||
won=1;
|
||||
for i=1:numP
|
||||
correct=0;
|
||||
guess=i;
|
||||
for j=1:numG
|
||||
m=drawers(guess);
|
||||
if m==i
|
||||
correct=1;
|
||||
break;
|
||||
end
|
||||
guess=m;
|
||||
end
|
||||
if correct==0
|
||||
won=0;
|
||||
break;
|
||||
end
|
||||
end
|
||||
idealSuccess=idealSuccess*(trial-1)/trial+won/trial;
|
||||
end
|
||||
disp(['Probability of success with random strategy: ' num2str(randSuccess*100) '%']);
|
||||
disp(['Probability of success with ideal strategy: ' num2str(idealSuccess*100) '%']);
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue