%SIMULATION OF DE MERE'S GAMES

%%% parameters 

p1=1-(5/6)^4;
p2=1-(35/36)^24;
p3=0.5;
n=5000;

s1=zeros(1,n);
s2=zeros(1,n);
s3=zeros(1,n);

clf reset;
%grid on;
ylim([0.4,0.6]);
hold on;
%h = axes('Position',[0 0 1 1],'Visible','off');

x=rand(1,n);
s1=(x<=p1);
x=rand(1,n);
s2=(x<=p2);
x=rand(1,n);
s3=(x<=p3);
t=[1:n];
plot(t, cumsum(s1)./t, 'Color', [0,1,0]);
hold on;
plot(t, cumsum(s2)./t, 'Color', [1,0,0]);
hold on;
plot(t, cumsum(s3)./t, 'Color', [0,0,1]);
hold on;
str1=strcat('prob. p1', sprintf('=%1.4f', p1));
str2=strcat('prob. p2', sprintf('=%1.4f', p2));
legend(str1,str2, 'prob. 0.5');
plot(t, 0.5+0*t, 'Color', [0,0,0]);
hold on;
xlabel('no. of games');
ylabel('re. freq. of wins');
 

title('Chevalier de Mere');

