Shared Birthdays

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

 

Search

Search WWW

Search DelphiForFun.org

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.)

Contact

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

Search DelphiForFun.org only

 

 

Here's a short Delphi program that lists the probability that at least two people share a common birthday in a room  containing N people.

The phrase "at least" in probability problems is a cue to  compute the probability of none and subtract that number  from 1. e.g. the probability that I have at least two socks of the same color in my drawer is 1- probability that there are not two  socks of the same color.

In the birthday case, the probability that no two people share the  same birthday out of two people (let's call it P2), is 364/365.  I  took one of the days, if you are not to share my day, yours had better be on one of the other 364.   Recall that by definition, probability of an outcome is the number of cases where that outcome occurs divided by the total possible outcomes. 

For three people the probability of none shared is P3=(364/365)*(363/365). For 4 the probability is P4= P3*362/365. You first three guys eliminated 3 choices so I have to choose one of the 362 remaining days if I'm not to share a birthday with any of you.   Etc, etc. etc.

We multiply these probabilities because of the rule of conditional probabilities, the probability of A and B both being true is the the probability that A is true times the probability that B is true, given the condition that A is true.   This is usually written as P(A,B)=P(A)*P(B|A).  In our birthday case, the probability that there are no shared birthdays among 4 people is the probability that there are no shared birthdays among the first 3 times the probability that the 4th doesn't match any of the others, once we know that they all have different birthdays.  We need this last condition to ensure that we have only 362 choices for that 4th guy's birthday.       

And again, remember that the probability of some shared birthdays is 1 - probability of no shared birthdays. That's it. 

So if after running this program you'll know that if you have 30 people in your class, there is a greater than 70% chance that 2 celebrate the same.  With 40 people, you can be 90% sure that at least two have the same birthday.  I'll take that bet. 

Addendum Sept 2, 2003: The above discussion ignores the possibility that someone in the room may have a birthday on February 29 during a leap year. I have had the code including that possibility for several months, but I had a difficult time explaining the revised calculation.   I finally tackled the write-up this weekend and posted it on a separate Shared Birthdays Leap year page.  The downloadable programs below have been revised and now report statistics with and without leap year considerations. 

Running/Exploring the Program 

bulletDownload source
bulletDownload  executable

Further explorations

Done Sept 2, 2003: By the way -- there is a small chance that someone in the room has a February 29  birthday .  How should this affect the calculation? 

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