Shared Birthdays w/ Leap year Considered

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]




Search WWW


As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.


Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 


We receive a few cents from each purchase.  Thanks


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search only




Shared Birthdays  - with leap years considered.

This is an extension of the Shared Birthdays discussion started here

On this page we'll investigate the probability that at least two people in a room with N people share a birthday and allowing for the possibility that some may have a birthday on February 29th. The are two mutually exclusive cases to consider:

1.)  Either everyone in the room has a unique birthday and no one has a Feb 29th birthday.  We will denote  the probability of this event as P1(N). Or ....

2.) Everyone in the room has a unique birthday and exactly one person has a Feb 29th birthday.  We'll call the probability of this P2(N).

These 2 cases do not overlap and cover all possibilities where everyone has a different birthday, so we may sum  the two probabilities and subtract from 1 to get the probability that two or more share a birthday. 

Case 1 - Unique birthdays and no Feb29th birthday

P1(N) is similar to the calculation used when we ignored leap year birthdays, except we allow for the fact that years average 365.25 days.  (I still ignore the 100 and 400 year leap year exceptions.)    The probability that first person has a unique birthday not Feb29th is P1(1)=365/365.25.    The probability that the second person does not have the 1st person's birthday and does not have a Feb 29th birthday is  (365/365.25)*(364/365.25).   For the 3rd person the probability is (365/365.25)*(364/365.25)*(363/365.25) and in general for the Nth person the probability P1(N) = P1(N -1)*(366-N)/365.25.

Case 2 - Unique birthdays and a single Feb 29th birthday

This case is more complicated.  The probability of person N being unique and meeting the single Feb 29th condition depends on whether the  Feb29th birthday already exists.   We'll call the probability in the  case where the Feb 29th slot is taken among the previous occupants P2a, and if Feb29th is not taken we'll call it P2b.  Again these are exclusive cases so we may add the probabilities to get the total probability of the event.  P2(N)=P2a(N)+P2b(N).   

Since we must have a single Feb29 birthday, for N=1 the probability is 1 chance in 1461, the number of days in four years when a leap year is included.  We can write this as P2a(1)= .25/365.25.  P2b(1)=0 of course. 

Now the second person enters the room.   If person #1 was not a Feb 29th, then by definition of this case, person #2 must be Feb 29th and  P2a(2)=(365/365.25)*(0.25/365.25).   If person #1 was a Feb29th then person number 2 must not be and   P2b(2)=(0.25/365.25)*(365/365.25).   Person #2 can celebrate any of the 365 days since person #1 had Feb 29th.   

In the general case  for P2a,   Feb 29th is already taken when person  N enters the room and  the probability of that is P2(N-1) by definition.  So   P2a(N)=P2(N-1)*(367-N)/365.25).   

For P2b, birthdays unique and Feb 29th not taken when N enters, just happens to be P1(N-1) so when N enters the room he must be a Feb 29th and  the probabilities are   P2b(N)=P1(N-1)*(0.25/365.25).

And just to complete the story.   

The probability of one or more shared birthdays for room with N randomly selected people is  1 -  (P1(N) + P2(N)).

The program displaying probabilities for N between 1 and 100 with and with the leap year calculation is available for downloading at Shared Birthdays  or below.

Running/Exploring the Program 

bulletDownload source
bulletDownload  executable


  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2018, Gary Darby    All rights reserved.