# HP Forums

Full Version: computing chances
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

(just a real life story, slightly to do with calculators; you may like it)

Once a year the "nationale wetenschapsquiz" (science quiz) is being held in the Netherlands. It consists of 20 questions that can be answered by knowing, reasoning or guessing. Every year in December the questions and answers are discussed in a television broadcast.

Back in the year 2000 question nr.11 was about 26 people (in a cafĂ©, but that part is not relevant to know): "what is the chance that 2 of these people have their anniversary on the same date?" You could choose from 30, 60 or 80 percent.

After some heated discussions about this question between several colleagues of mine, I simply reasoned the answer out. After this it was a matter of calculating the formula, were it not that most calcs cannot do this in one go.

Now my questions are: What is the answer and how did you compute it on which HP calc?

Bram

This is known as the "birthday problem" or "birthday paradox", though in my opinion there's no paradox involved.

The probability that two people out of n share the same date is 1 minus the probability that they each have a unique date.
Disregarding leap days, for n people, the probability of all having unique dates is 365Cn/365^n.

Here is an untested program for the HP-41, run with n in X:

```LBL BP
1
LBL 01
366
RCL ST Z
-
*
365
/
DSE ST Y
GTO 01
1
X<>Y
-
END
```
The program starts with a probability of 1, uses an index variable i (on the stack) which counts down from n to 1, and at each step multiplies by (366-i)/365. This results in the probability of no match; the result is then subtracted from 1 to get the probability of a match.

A similar program (also untested) should work on most other RPN calculators by storing the iteration variable in a numbered register rather than on the stack:

```LBL B
STO 0
1
LBL 1
366
RCL 0
-
*
365
/
DSZ 0
GTO 1
1
X<>Y
-
R/S
```

Quote:
the probability of all having unique dates is 365Cn/365^n.

Shouldn't this be 365Pn/365^n?

1 - 365Pn/365^n = 0.598240820 or 59.8% (for n=26), in accordance with your (tested) HP-41 program.

To start with, the heated discussions were about the precise meaning of the question. Was or wasn't it allowed to have a date with more than 2 anniversaries? Was or wasn't it allowed to have (more than) 2 couples of anniversaries? To my opinion the question means in normal every day language that we are interested in knowing the chances of an occurrence that at least two people celebrate on the same day. I came to that conclusion (and to a computable answer) by reversing the question: how about each and every of the lot celebrating on different days?

That's very easy to answer by the definition of 'chance':

# wanted situations / # possible situations.

# wanted situations = 365x364x363...x340 (365!/(365-26)!)

# possible situations = 365x365x365...x365 (365**26)

(of course you'll have to change 365 by 366 for a leap year, but that doesn't make much difference)

With for example Free42 (a real HP-42S is slightly too "limited") you can easily calculate the quotient directly, but otherwise you'll have to program (almost any HP calc will do).

Chance=1 ; FOR i=0 TO 25 ; Chance=Chance*(365-i)/365 ; NEXT

which may translate for the HP-41C(V) into this:

```*LBL CHANCE
1
-
1000
/
STO 00
1
STO 01
*LBL 01
365
RCL 00
INT
-
ST* 01
365
ST/ 01
ISG 00
GTO 01
RCL 01
```
26 XEQ CHANCE => 0.40(17591805)

The answer 0.40 is the answer for the reversed question. So the answer to the original question is 1-0.40 => 0.60.

So take 26 people at random, for example 26 readers of the HP museum forum and there's 60% chance that at least 2 of them were born on the same day in the year.

And that's an unexpectedly high value, isn't it?

With an increasing number of people the chance for 'all different dates' will approach zero and hence the chance for 'a duplicate' will approach certainty. With 366 or more people a duplicate will have become certain.

Strangely enough, when I would ask (the other way round) for the chance for the existence of a date on which nobody has his/her birthday then this chance will never be equal to zero, no matter how many people I put together. Hard to believe that even for the entire Dutch population (about 16 million persons) there's a chance, albeit extremely low, that on one (or more!) date(s) nobody celebrates his/her birthday. It will never happen, but there is a chance ...

Quote:
Shouldn't this be 365Pn/365^n?

Yes, the "C" was a misteak.