This is my Ruby translation to Peter Norvig's solution to When is Cheryl's Birthday problem.
-
Albert and Bernard just became friends with Cheryl, and they want to know when her birthday 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?
View Peter Norvig's solution translate in Ruby:
- Create abstraction for cheryl's possible dates
- Cheryl tells part of birthday
- Person knows birthday if possible date only one
- Statement 3 - Albert: I don't know when Cheryl's birthday is, but I know that Bernard does not know too
- Statement 4 - Bernard: At first I don't know when Cheryl's birthday is, but I know now
- Statement 5 - Albert: Then I also know when Cheryl's birthday is
- So when is Cheryl's birthday?
See norvig/pytudes - Python programs to practice or demonstrate skills, it's gold.