Write a program to solve the classic “Einstein Riddle”. You can use Java, Python, R, C/C++.
This classic riddle is claimed to have been written by Einstein but it is sometimes also attributed to Lewis Carrol, although there's no evidence that either of them actually wrote it. Regardless, it is an interesting problem that can be solved by logic but it also lends itself nicely as an AI programming exercise. There are many ways to code for this riddle – you are free to choose any approach you want. The riddle is:
There are five houses in five different colours in a row. In each house lives a person with a different nationality. The five owners drink a certain type of beverage, smoke a certain brand of cigar and keep a certain pet. No owners have the same pet, smoke the same brand of cigar, or drink the same beverage. Other facts:
The Brit lives in the red house.
The Swede keeps dogs as pets.
The Dane drinks tea.
The green house is on the immediate left of the white house.
The green house's owner drinks coffee.
The owner who smokes Pall Mall rears birds.
The owner of the yellow house smokes Dunhill.
The owner living in the centre house drinks milk.
The Norwegian lives in the first house.
The owner who smokes Blends lives next to the one who keeps cats.
The owner who keeps the horse lives next to the one who smokes Dunhill.
The owner who smokes Bluemasters drinks beer.
The German smokes Prince.
The Norwegian lives next to the blue house.
The owner who smokes Blends lives next to the one who drinks water.
The question is: who owns the fish?
This question belongs to programming and discusses about solving a classic Einstein’s riddle using programming.
Download Full Solution