The probability that two students in a class have the same birthday is at least 75%. What is the minimum size of the class?
I tried,
Prob_Birthday <-1
Prob_Min = 0.75
Max_Class_Size = 40
Stop = FALSE
for (k in 2:Max_Class_Size){
if(Stop == FALSE){
Prob_Birthday[k]<-1-prod(365:(365-(k-1)))/365^k
if(Prob_Birthday[k]>=Prob_Min){
print("Found")
print(Prob_Birthday[k])
print(k)
Stop = TRUE
}
}
}
if(Stop == FALSE){
print("Probability not found, try increasing class size")
}
But this code proves every class size until 40; so I can get when the size when the probability = 75%, (size = 32, when the probability = 75%). Even though, that's inefficient.
How could I find the only size of the class when the probability is 75%?
The probability that $k$ people chosen at random do not share birthday is: $$ \dfrac{364}{365} \cdot \dfrac{363}{365} \cdot \ldots \cdot \dfrac{365-k+1}{365}. $$
If you want to do it in
R, you should use vectorised operations orRwill heavily penalise you in performance.