Message Boards Message Boards

7 Replies
4 Total Likes
View groups...
Share this post:

How to find the probability for two people who have the same birthday among

Posted 10 years ago
 Here is the problem. Please write down it using the mathematica.

How to find the probability for two people who have the same birthday among the 100 people?

Firt we have 365 days for a year, then we random select 2 people from 100, and see what is the probability.

I am a newer for mathematica, please write the mathematica, so I can study on it.

Many thanks. and ASAP
POSTED BY: michelle yrw
7 Replies
Posted 10 years ago
POSTED BY: michelle yrw
Dear Craig, 

I am not really sure about the original question either. You are absolutely right: In fact, I did read it as
"How to find the probability for (at least/any) two people who have the same birthday among the 100 people?"

Without any quantifier like "exactly" that is the default mathematical interpretation, I believe. Otherwise I would have expected the question to explicitely state "exactly two people".
Here is the usage I adhered to:
Two queens are red.To a layperson (i.e. in everyday language), or in some mathematical contexts, this means "there are exactly two red queens". But in logical, it gets unpacked as "there exist two queens which are red" which is true as long as there are at least two red queens. In cases like these, it's usually a good idea to add at least or exactly to avoid any possible confusion.

You are quite right that Michelle's question might have been about exactly two people. And as you say, the question you answer is"  ..., exactly two people out of 100."  which is a different question to the one I wanted to answer.

By the way, the question could technically also mean exactly two people share their birthdays and none of the remaining 98 people share their birthdays with anyone - so there is no other couple of people sharing the same birthday (which might be different from the first couples').

POSTED BY: Marco Thiel
Posted 10 years ago
:Thank you,

For how long it takes me for writing the mathematica without asking questions here, or help others?

Both pictures are very nice.
POSTED BY: michelle yrw
You are welcome.

For how long it takes me for writing the mathematica without asking questions here, or help others?

Between 0 and 25 years! I believe that anyone--who is interested--can write useful code in less than an hour by following examples here and in the help browser.
However, I am still learning how to write code and to help others after nearly 25 years.
POSTED BY: W. Craig Carter
Isn't the "classical" question usually, "For N people, what is the probability that at least 2 share the same birthday?"  I believe that is the solution to that is given by Marco.  But, the original question seemed to be exactly two people out of 100.  The "at least" probability would need to multiplied by the probability none of the other 98 share the same birthday as our lucky two.

So, let's try an approximation by brute force for exactly 2:
experiment := Max[Length /@ Gather[RandomInteger[{1, 365}, 100]]]
Histogram[Table[experiment, {10000}], {1}]

N@Count[Table[experiment, {100000}], 2]/100000

Playing with this a bit more: brute force probabilities that  for n people,  at most m share the same birthday:
exper[i_] := Max[Length /@ Gather[RandomInteger[{1, 365}, i]]]

probs = ParallelTable[((N@Count[Table[exper[#], {10000}], i]/10000) &) /@ Range[100], {i, 1, 10}]

ListPlot[probs, PlotRange -> All, Frame -> True,
AxesOrigin -> {0.5, 0.5},
FrameLabel -> {"Number of People", "Probability"},
PlotLegends -> Range[10]]

The crossings at p=1/2 are interesting.....
POSTED BY: W. Craig Carter

this seems to be a very typical homework problem.

The probability that two randomly selected people share their birthdays is 1/365 or in Mathematica:
1/365 //N

If you want to know what the probability is that at least two people (any two persons) share their birthdays, it is quite close to one.
1 - 365!/(365^100 (365 - 100)!) // N[#, 20] &

Here's a table with the probabilities for up to 30 people
Table[1 - 365!/(365^i (365 - i)!) // N[#, 20] &, {i, 1, 30}]
A typical homework problem is also how many people do you need in a room so that the probability that two share their birthdays is more than 50%. The answer would be
i = 1; While[Less[1 - 365!/(365^i (365 - i)!), 0.5] // N[#, 20] &, i++]; Print[i]
which gives 23. This figure illustrates that:
Show[Table[1 - 365!/(365^i (365 - i)!) // N, {i, 1, 100}] // ListLinePlot, Plot[0.5, {x, 0, 100}]]

There are fantastic demsontration projects out there, e.g.

All of these come with the Mathematica code. There are even generalisations of the problem:

If you google "Mathematica birthday problem" you find fantastic information such as:

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract