# This program calculate the theoretical probabilites for the # classical birthday problem. # In addition, we simulate the outcome of birthdays and identify # the dates which at least two persons were given birth in a group # of n. # Created 040315 by C. Andy Tsao. library(MASS,survival) psbd<-function(x,n) {a<-x-1; b<-x-n+1;v<-1-prod(b:a)/x^(n-1);return(v)} x<-365; daylist<-seq(1:x) n<-73; psbd(x,n); ssample<-sort(sample(daylist,n,replace = TRUE)); ssample; duptf<-duplicated(ssample) dupdates<-ssample[duptf==TRUE] as.date(dupdates)