Created
August 17, 2016 09:15
-
-
Save joshy/4564f199a2fe1a04b6ec14cdb942170d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Statements | |
1. 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 | |
2. Cheryl then tells Albert and Bernard separately the month and the day of the birthday respectively. | |
3. Albert: I don't know when Cheryl's birthday is, but I know that Bernard does not know too. | |
4. Bernard: At first I don't know when Cheryl's birthday is, but I know now. | |
5. Albert: Then I also know when Cheryl's birthday is. | |
""" | |
DATES = [ | |
'May 15', 'May 16', 'May 19', | |
'June 17', 'June 18', | |
'July 14', 'July 16', | |
'August 14', 'August 15', 'August 17' | |
] | |
def Month(date): | |
return date.split()[0] | |
def Day(date): | |
return date.split()[1] | |
def tell(part, possible_dates=DATES): | |
"""Cheryl tells a part of her birthdate to someone: | |
return a new list of possible dates that match the part | |
""" | |
return [date for date in possible_dates if part in date] | |
def know(possible_dates): | |
" A person knows the birthday if they have exactly one possible date." | |
return len(possible_dates) == 1 | |
def cheryls_birthday(possible_dates=DATES): | |
"""Return a list of the possible dates for which statements | |
3 to 5 are true.""" | |
return filter(statements3to5, possible_dates) | |
def statements3to5(date): | |
return statement3(date) and statement4(date) and statement5(date) | |
def statement3(date): | |
return False | |
def statement4(date): | |
return False | |
def statement5(date): | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment