% [birth_02b.m]< [birth_02.m] 2014.11.14
% For different values of k, k people pick a number from $\{1, \dots n\}$.
% Find the LARGEST value of n so that:
% The probability that {\bf AT LEAST 2} pick the same number
% is greater than tolerance. This is the same as q <= (1 - tolerance)
% where q = Prob( all different birthdays)
tolerance = input('what is the tolerance? ');
% enter range as vector
range = input('what is the range. e.g. [5: 5: 100] ?');
store = []; % start with an empty storage vector
for k = range;
n = k; % for n < k-1, prob at least 2 pick same = 1 (pigeon hole principle)
q = 0; % when n = k the probability is virtually 0
while q < 1 - tolerance
n = n + 1;
a = [n: -1 : (n-k+1)];
b = (1/n)*(a);
q = prod(b);
endwhile
store = [store; k (n-1)]; % concatenate new values
endfor
disp('tolerance = '), disp(tolerance)
disp(store)