-
-
Save leehambley/18874bada1d3a2c5c8b2 to your computer and use it in GitHub Desktop.
This file contains 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
DATES = [ | |
"May 15", "May 16", "May 19", | |
"June 17", "June 18", | |
"July 14", "July 16", | |
"August 14", "August 15", "August 17" | |
] | |
def month(date); date.split[0]; end | |
def day(date); date.split[1]; end | |
def tell(part, possible_dates=DATES) | |
possible_dates.select{|d| d.include? part} | |
end | |
def know(possible_dates) | |
possible_dates.length == 1 | |
end | |
def albert_doesnt_know_but_knows_bernard_doesnt_know_either(date) | |
possible_dates = tell(month(date)) | |
!know(possible_dates) && possible_dates.none?{|d| know(tell(day(d)))} | |
end | |
def at_first_bernard_doesnt_know_but_knows_now(date) | |
at_first = tell(day(date)) | |
!know(at_first) && know(at_first.select{|d| albert_doesnt_know_but_knows_bernard_doesnt_know_either(d)}) | |
end | |
def then_albert_also_knows(date) | |
know(tell(month(date)).select{|d| at_first_bernard_doesnt_know_but_knows_now(d)}) | |
end | |
def cheryls_birthday(possible_dates=DATES) | |
possible_dates.select do |d| | |
albert_doesnt_know_but_knows_bernard_doesnt_know_either(d) && | |
at_first_bernard_doesnt_know_but_knows_now(d) && | |
then_albert_also_knows(d) | |
end | |
end | |
puts cheryls_birthday # => July 16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment