When is Cheryl's Birthday?¶
Peter Norvig, April 2015
This logic puzzle has been making the rounds:
Albert and Bernard just became friends with Cheryl, and they want to know when her birtxhday is. Cheryl gave them a list of 10 possible dates:
May 15 May 16 May 19 June 17 June 18 July 14 July 16 August 14 August 15 August 17
Cheryl then tells Albert and Bernard separately the month and the day of the birthday respectively.
Albert: I don't know when Cheryl's birthday is, but I know that Bernard does not know too.
Bernard: At first I don't know when Cheryl's birthday is, but I know now.
Albert: Then I also know when Cheryl's birthday is.
So when is Cheryl's birthday?
Problem-Solving Tools¶
Cheryl's puzzle was designed to be solved with a pencil, the greatest problem-solving tool in the history of mathematics (although some prefer a pen, chalk, marker, or a stick for drawing in the sand). But I will show how to solve it with another tool: computer code. I choose this tool for four reasons:
- It is a more direct way to find the solution. All I have to do is faithfully describe the problem with code that says: "for each of the 10 possible dates, tell Albert the month and Bernard the day and check if statements 3 through 5 are true." The intended pencil and paper solution requires not just understanding the problem, but also creatively discovering the steps of the solution—a harder task.
- With tested, debugged code, you're less likely to make a mistake that leads you to a wrong answer.
- You'll learn how to solve problems that are similar, but can't be solved with pencil and paper because they have millions of possibilities rather than just 10.
- Solving puzzles is fun; programming is fun; solving puzzles with programs is double fun.
We will translate each of the 6 statements in the puzzle into Python code: