The Zebra puzzle is a classic logic puzzle. It is sometimes attributed to Albert Einstein and sometimes to Lewis Carroll. The version here is taken from Life International 1962.
There is a row of five houses.
The Englishman lives in the red house.
The Spaniard owns the dog.
Coffee is drunk in the green house.
The Ukrainian drinks tea.
The green house is immediately to the right of the ivory house.
The Winston smoker owns a snake.
Kools are smoked in the yellow house.
Milk is drunk in the middle house.
The Norwegian lives in the first house.
The man who smokes Chesterfields lives in the house next to the man with the fox.
Kools are smoked in the house next to the house where the horse is kept.
The Lucky Strike smoker drinks orange juice.
The Japanese smokes Kents.
The Norwegian lives next to the blue house.
Your mission is to write a logic program that faithfully embodies these constraints and is capable of determining who owns the zebra. (No fair solving the puzzle yourself and building in the answer.) In order to help you write your program and in order for us to understand it, we request that you use the following conceptualization and vocabulary.
There are 5 nationalities - english, japanese, norwegian, spanish, and ukrainian. There are 5 animals - fox, horse, snake, dog, and zebra. There are 5 types of cigarettes - kool, chesterfield, winston, lucky, and kent. There are 5 types of drinks - beer, coffee, juice, milk, and tea. There are 5 house colors - blue, green, red, white, and yellow.
A house is a 5-tuple consisting of a nationality, an animal, a cigarette, a drink, and a color. We designate houses using the constructor h and symbols for the components. For example, the term h(english,snake,winston,milk,red) refers to a red house that is owned by an Englishman, who owns a snake, smokes Winstons, and drinks milk.
A block is a 5-tuple consisting of 5 houses in order from left to right. For example, the term block(h(...),h(...),h(...),h(...),h(...)) is a block (once we fill in the ellipses).
A block is legal if and only if it satisfies the constraints above. For example, we would write legal(block(h(...),h(...),h(...),h(...),h(...))) to say that block(h(...),h(...),h(...),h(...),h(...)) is legal. Your job in this assignment is the define the legal relation. Once we compute a legal block, we know who owns the zebra as well as ll sorts of other things.
A few points in the interest of clarity. Each of the five houses is painted a different color. The inhabitants are of different national extractions, own different pets, drink different beverages, and smoke different brands of American cigarettes. And, in statement 6, right means your right.
Directions: Write a logic program to solve the problem, paste your rules in the box below, and press Submit.