%Coupons, recursive solution
%parameters

for (n=[5:15])
%n=60;

%kmax=floor(4*n*log(n));
%kmax=45;

kmax=100;

pr=zeros(kmax,n+1);
pr(1,1)=1;

for (k=[2:kmax])
    for (r=[2:n+1])
        pr(k,r)=pr(k-1,r)*(r-1)/n+pr(k-1,r-1)*(n-r+2)/n;
    end;
end;
 
for (k=[n:kmax-1])
     display(sprintf('%d %1.8f', k, pr(k+1,n+1)));
end

%clf reset;
xlim([5,kmax]);
ylim([0,1]);
hold on;
plot([n:kmax-1], pr((n+1):kmax,n+1), 'Color', [n/60,0,1-n/60]);
%plot([1200:kmax], pr(1200:kmax), 'Color', [1,0,1]);
 
 
str=strcat('Prob. that all birthdays are represented with ', sprintf(' 5<=n<=%d', n));
title(str);
xlabel('k');
ylabel('prob.');
hold on;
end

hold off;

 
 
