Created
May 9, 2014 14:15
-
-
Save cbarraford/76a298b36513d2e8fc8c 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
Celebrity, and only the celebrity, meets these criteria: | |
- celebrity does not know anyone at the party | |
- everyone at the party knows the celebrity | |
knows(a, b) => true if a knows b | |
false if a does not know b | |
knows(a, b) does not imply knows(b, a) |
mattwhite
commented
May 9, 2014
def find_celebrity(people)
people.delete_at(knows(people[0], people[1]) ? 0 : 1) while people.length > 1
people.first
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment