%% Birthday Problem
% Among N people, what is the probability that there
% is a pair with the same birthday    (day/month)
clear all
close all


  disp('Birthday Problem')
  lw = 2; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;
%


nobrtd = []; product=1; N=10; 
for i = 1:N
product = product * (365-i+1)/365; % probability that i people
                                   % all  have different
                                   % birthdays
nobrtd = [nobrtd product];         % save this probability
end
plot((1:N), 1-nobrtd,'*')
hold on
plot(23,0,'o', 23, 1-nobrtd(23),'ro','Markersize',10)
plot((1:N), 0.5 * ones(1,N),'r:')
xlabel('Number of people')
ylabel('Probability of a match')
axis tight
%find(1- nobrtd > 0.5)

x=1-nobrtd(23);   %0.5073
disp(['For N=23 people the probability is ', num2str(x,5)]);
x=1-nobrtd(N)       %0.9999996928
disp(['For N=100 people the probability is ', num2str(x,10)]);

