# Programming probability.

• Oct 1st 2007, 01:13 AM
Malicant
Programming probability.
Hi all, this is my first post.

I'm a second year computer programming student and we've just been given our first assignment for this symester. The problem in to design a program that can work out how many people need to be in a room for the probability of 2 people sharing the same birthday to be greater than 0.5.

I'm not very good at probability but I had a go none the less. Here's what i came up with.

If there are two people in a room, the probability of them sharing the same birthday would be 1/365. If there were 3 people then the probability would be 2/365.

I don't think it's this simple at all and I'm not sure how to factor leap years into this. Any help on this would be really cool, thanks all :).
• Oct 1st 2007, 02:01 AM
Soroban
Hello, Malicant!

Welcome aboard!

Quote:

The problem is to design a program that can work out
how many people need to be in a room for the probability of 2 people
sharing the same birthday to be greater than 0.5.

If there are two people in a room, the probability of them
. . sharing the same birthday would be 1/365. . . . . Yes!
If there were 3 people then the probability would be 2/365. . . . . no

With 3 people, look at the opposite probability: no one shares a birthday.

The first person can have any birthday: $\displaystyle \frac{365}{365}$

The second must have a different birthday: $\displaystyle \frac{364}{365}$

The third must have yet another birthday: $\displaystyle \frac{363}{365}$

Hence: .$\displaystyle P(\text{different birthdays}) \:=\:\frac{365}{365}\cdot\frac{364}{365}\cdot\frac {363}{365} \:=\:\frac{132,132}{133,225}$

Therefore: .$\displaystyle P(\text{common birthday}) \;=\;1 - \frac{132.132}{133.225} \;=\;\frac{1093}{133,225} \:\approx\:0.0082$

We want $\displaystyle n$ people to share (at least) a birthday with probability greater than 0.5

The probability that none of them have the same birthday is:

. . $\displaystyle \underbrace{\frac{365}{365}\cdot\frac{364}{365}\cd ot\frac{363}{365}\cdot\frac{362}{365}\:\cdots\;\fr ac{366-n}{365}}_{n\text{ fractions}}$

When this product drops below 0.5, we've found it!

I trust you can write the program now . . .

• Oct 1st 2007, 02:14 AM
Malicant
Yes!, i get it :). Thank you so much for your help. Now that I know this, the rest should be a breeze. Thank you again :).