% % Written by: % -- % John L. Weatherwax 2006-12-31 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- clc; close all; max_n_people_ahead = 50; % Compute the probability that we have identical birthdays among n people: % prob_n_nonmatching_bdays= []; for n=1:max_n_people_ahead, num = 365-(n-1); den = 365.; p = num/den; if( n==1 ) prob_n_nonmatching_bdays = 1.; else prob_n_nonmatching_bdays = [ prob_n_nonmatching_bdays, prob_n_nonmatching_bdays(end) * p ]; end end prob_of_win = prob_n_nonmatching_bdays .* ( (1:max_n_people_ahead)/365 ); plot( 1:n, prob_of_win ); xlabel( 'number of people ahead in line' ); ylabel(' probability of winning a free ticket' ); saveas( gcf, 'prob_of_win_at_position_np1', 'epsc' ); % print the best spot [v,spot] = max( prob_of_win ); v spot