Programming the Matching Birthday Problem

Published:  04/06/2014

In a previous post, I solved a fairly famous probability problem about two or more people having a matching birthday (in a room of size n). In this post, I will show you how to program a Texas Instruments graphing calculator to perform the calculations. The result will provide you with a handy program to impress your friends while also teaching you a little about writing programs in the TI-83 graphing calculator.

First, let's state the problem, and the solution we derived in the earlier post.

The Problem

Ignoring leap years, find the probability that a room containing n people has at least two people with the same birthday (same month and day, not year).

The Solution

P(at least one pair of matching birthdays) = 1 - P(no one in the room of size n has the same birthday)

P(at least one pair of matching birthdays)= 1 - [365/365*364/365*...*(365 - n + 1)/365].

The Algorithm

To program our graphing calculator, we need to create a step-by-step procedure that we will turn into code for the TI-83.

Step one: Establish n (the number of people in the room).

Step two: Store n in a variable called "N."

Step three: Create a count variable called "C."

Step four: Initiate the count variable, C, to 1.

Step five: Create a variable called "F" to store our probability fraction, and initialize it to 1.

Step six: Check if N > C. If it is, advance to step seven. Otherwise, proceed to step eleven.

Step seven: Perform the following calculation: F*(365 - C)/365

Step eight: Store the result of the calculation from step seven into variable F.

Step nine: Increase C by 1.

Step ten: Return to step six.

Step eleven: Store (1 - F) into a variable called "A."

Step twelve: Output A, because it is our answer.

The Program

Translating this program into the TI-83 requires use of the calculator's syntax. I taught myself without the aid of a manual or even a Google search. The calculator's syntax is pretty intuitive, so let's code the algorithm just the way I did, by just diving right in. Watch the video below to see how easy it is.

Some Results

  • If a room has 23 people in it, there is a 0.507 (50.7%) probability of having at least two people with the same birthday.  
  • If a room has 30 people in it, there is a 0.706 (70.6%) probability of having at least two people with the same birthday.  
  • If a room has 50 people in it, there is a 0.970 (97.0%) probability of having at least two people with the same birthday.  
  • If a room has 70 people in it, there is a 0.999 (99.9%) probability of having at least two people with the same birthday.