Trouble with solution JordiB 13th September, 2009 13:42 (UTC)

The probability that N people all have a different birthday is (assuming a year always has 365 days, in Matlab):

```prob = 1;
for n=0:n-1
prob = prob * (365-n) / 365;
end```

Or: 365! / (365-N)! / 365^N (but Matlab cannot calculate that number)

The probability that two or more people share a birthday is 1 minus that probability. When there are 23 people this chance is >50% and when there are 41 people it is >90%.

I seem to be a little bit stuck with the final solution.

My reasoning is that I can calculate the probability of exactly two people sharing a birthday by first calculating the chance that N-1 people have different birthdays and then multiplying by the chance that the last person has his birthday on one of the other people's birthdays:

`365! / (365-(N-1))! / 365^(N-1) * (N-1) / 365`

This number would be larger than the previous one iff (N-1) > (365-(N-1)). In other words, when N > 183.5, so if this is correct, then it is never very likely that exactly 2 people share a birthday (because the total number is under 150). Actually, in order for this to be the most likely, the probability should also be higher than the probability that more than 2 people share a birthday (which we should be able to determine by subtracting the sum of the earlier mentioned probabilities). When there are 184 people, and according to my calculations the chance of one shared birthday would by higher than the chance of none for the first time, the odds of two or more shared birthdays are overwhelming (1 according to Matlab).

What am I doing wrong?