Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

While reading through about the birthday problem on Wikipedia, I came across some of the variations described in formulating the problem, notably

Another generalization is to ask how many people are needed in order to have a better than 50% chance that two people have a birthday within one day of each other, or within two, three, etc., days of each other.


A related question is, as people enter a room one at a time, which one is most likely to be the first to have the same birthday as someone already in the room? That is, for what $n$ is $p(n) − p(n − 1)$ maximum? The answer is 20—if there's a prize for first match, the best position in line is 20th.

So a question would be, which position in the line of people entering the room has the highest probability of the person at that position having a birthday within 2, (or say $k$) days of somebody already in the room?

What about for the problem with 3 people? What positions would have the highest probability of winning the prize, if there is a prize for the first triplet that share the same birthday?


Say as people enter the room, \$100 is awarded to the first person (called A) who enters the room and shares a birthday with someone already in the room, and \$1000 is awarded to the first person (called B) who enters the room and shares the same birthday with two people already present (not necessarily A). Then which positions yield the best chances of winning the \$100 or the \$1000?


The maths for this is probably quite wrangled. I don't mind if somebody uses a simulation to answer my questions. Preferably code that is easily portable, like Python or Fortran, maybe C or Matlab.

This could keep on getting more complicated. How many people do we need in a room before the chances of three people having birthdays within a day of each other exceeds 50%? And again, if we have people troop into the room sequentially, which positions stand the best chance of being in that triplet?

When I learnt of this simple fact in first year maths I didn't think it had so many interesting shades!

Thank you.

share|cite|improve this question

It is probably better to ask one question at a time.

For the question

What positions would have the highest probability of winning the prize, if there is a prize for the first triplet that share the same birthday?

then any of the first three to enter the room is most likely to be in the first triplet.

If the prize is for the third of the triplet then I think you can work out the probability $p(n,d)$ that after $n$ people have entered the room there are $d$ pairs and no triplets, using the recursion something like

$$p(n,d) = \frac{(365-n+1+d)\,p(n-1,d) + (n-2d+1)\,p(n-1,d-1) }{365}$$

starting at $p(0,0)=1$ and $p(0,d)=0$ for $d \not = 0$, assuming there are 365 equally likely and independent birthdays. This is easily coded.

You then want to find $n$ such that the probability of being the third of the first triplet $\sum_d p(n-1,d) - \sum_d p(n,d)$ is maximised, which I think may be about $n=85$ with a probability of about 0.0116385.

If you just look at $p(n,0)$, then this reduces to the earlier second of the first pair problem, looking for where $p(n-1,0)-p(n,0)$ is maximised, which is indeed with $n=20$ and a probability of about 0.0323.

share|cite|improve this answer
I've just edited my question(s) to facilitate discussion of the question you answered. You're saying to win the \$100, position 20 is the best to be at, and to win the \$1000 it's position 85, correct? – Samuel Tan Dec 22 '11 at 2:13
Yes, but eve then the odds of winning are low – Henry Dec 22 '11 at 7:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.