birthday paradox, one by one

An easy riddle, riding the birthday paradox. Namely how many people on average have to sequentially enter a room for a double birthday to occur?

The answer is straightforward,

\sum_{n=2}^{366}n\prod_{m=1}^{n-2}\left(1-\frac{m}{365}\right)\frac{n-1}{365}

as only the last person in can share a birthday with those already in. This sum equals 24.62. Since the “magic number” is 23, this may sound wrong but the median attached to the above distribution is truly 23. My R code is

q=rep(1,a<-366)/365
for(n in 3:a)q[n]=q[n-1]*(1+1/(n-2)-(n-1)/365)
sum(q[-1]*(2:a))

2 Responses to “birthday paradox, one by one”

  1. R has the neat `pbirthday` function, which does exactly what you think it does. Unfortunately it isn’t vectorized. You can get the same answer with
    n = 1:365
    sum(n * (1-sapply(n-1, pbirthday)) * (n-1)/365)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: