Birthday Buddies

In a group of 23 people, there is a 50% chance that 2 people have the same birthday. By the time you get past 50ish people, that number effectively becomes 100%.

The first time my little reptile brain heard that “paradox” it gave me a headache. There are 365 days in a year, so the odds of two people having the same birthday, should be like, less than 1%, right? So even multiplying that through a bigger sample – surely couldn’t get to 50%? Right? RIGHT?

I was about to get crazy, and try to pull Facebook API’s, census records, or make more friends in order to create a significant number of groups, and see if I can get to 50%. Because I don’t learn math by numbers, I learn math by breaking stuff. Then I remembered something. I have Python. And, like what we explored in fictional friends, I can just make up people and have the same effect.

Methodology

  1. Using Python, create a function to create a script to create people, with an ID, Name, and a random birthday.
  2. Using Python, create a function to create a group of people, which calls the “Create Person” function, a number of times (ideally 23 to test)
  3. Using Python, create a function, creating groups a significant number of times, to create “matches”, returning the match back, with the independent variable being group-size and the dependent variable being how many groups had a match (represented as a probability).
  4. Run, graph, analyze

Code Review

Checkout the repo here, for how it’s done. Why did I name people? Because people, even fictional people, deserve a name.

Results

I ran 1,000 simulations of each group size ranging from 2, to 100 to examine each probability. At a group size of 23, 478 groups had matches, meaning the probability was 47.8%. At 25, it jumped to 53%.

How is this possible? Why is this so confusing?

It’s because we’re looking at pairs of people, not individuals, and not compared to a certain date. For example, we’re not talking about 23 individuals, we’re talking about 253 possible pairs.

23×222=253 \frac{23 \times 22}{2} = 253

Of if you want to calculate possible pairs in this case, it would be…

n×(n1)2=x\frac{n \times (n-1)}{2} = x

After you adjust the math for pairs, you find the lambda…

λ=253365=0.693λ = \frac{253}{365} = 0.693

So now we calculate the probability of no matches…

e0.693e^{-0.693}

So to calculate the probability of a match, just subtract 1 minus the probability of no matches…

P=1(2.718)0.693=.50P=1-(2.718)^{-0.693} =.50

Why did I add 2.718 in for e? Because it’s a rough constant, like π3.14159\pi \approx 3.14159

. Don’t worry, I had to look it up too.

Sanity check! Let’s do the same thing for 50 groups.

So for example, a group size of 50 would be…

50×492=1,225\frac{50 \times 49}{2} = 1,225
λ=1225365=3.356λ = \frac{1225}{365} = 3.356
NoMatches=0.0348No Matches = 0.0348
Probability=.9652Probability = .9652

In the simulation, when I did it “for real” 969 groups had a match, so roughly 96.9% probability. Pretty close!

Math is neat.

Stay Curious!


Discover more from The Curiosity Project

Subscribe to get the latest posts sent to your email.

Comments

Leave a Reply

Discover more from The Curiosity Project

Subscribe now to keep reading and get access to the full archive.

Continue reading