Solve the zebra puzzle.
Each of the five houses is painted a different color, and their inhabitants are of different national extractions, own different pets, drink different beverages and smoke different brands of cigarettes.
Which of the residents drinks water? Who owns the zebra?
Implement the waterDrinker
and zebraOwner
methods from the ZebraPuzzle
class.
They must return a string each, whose values are the answers to the zebra-puzzle questions "Who drinks water?" and "Who owns the Zebra?".
Each answer will be one of the resident's nationalities: Englishman, Spaniard, Ukrainian, Norwegian, or Japanese.
Obviously, you could simply write two single-statement function if you peek at the test program to see the expected solution. But the goal is to develop an algorithm which uses the given facts and constraints for the puzzle and determines the two correct answers.
Sign up to Exercism to learn and master JavaScript with 32 concepts, 140 exercises, and real human mentoring, all for free.