IX. Who Owns the Zebra? The real world often poses what are called constraint satisfaction problems, where the task is to find a feasible solution. In other words, we don't have to optimize anything, but we have to satisfy all of the problem's constraints instead. One of the best-known examples of a constraint satisfaction problem is the famous "Zebra" problem. It goes like this: There are five houses, each of a different color and inhabited by men of different nationalities, with different pets, favorite drinks, and cars. Moreover, 1. The Englishman lives in the red house. 2. The Spaniard owns the dog. 3. The man in the green house drinks cocoa. 4. The Ukrainian drinks eggnog. 5. The green house is immediately to the right (your right) of the ivory house. 6. The owner of the Oldsmobile also owns snails. 7. The owner of the Ford lives in the yellow house. 8. The man in the middle house drinks milk. 9. The Norwegian lives in the first house on the left. 10. The man who owns the Chevrolet lives in the house next to the house where the man owns a fox. 11. The Ford owner's house is next to the house where the horse is kept. 12. The Mercedes-Benz owner drinks orange juice. 13. The Japanese drives a Volkswagen. 14. The Norwegian lives next to the blue house. The question is... who owns the zebra? Furthermore, who drinks water?
226 IX. Who Owns the Zebra? Several sentences provide direct information. For example, sentence 8 says that milk is consumed in house 3 (i.e., the middle house). Sentence 9 tells us that the Norwegian lives in house 1 (i.e., the first house on the left). Sentence 14 indicates that house 2 is blue (as this is the only house next to the Norwegian). So, the current knowledge we have is Color blue Drink milk Country Norwegian Car Pet Two other sentences are of immediate interest. Sentence 1 says that the Englishman lives in the red house, and sentence 5 says that the green house is immediately to the right of the ivory house. The conclusions are that House 1 is not red (because it's occupied by the Norwegian). Either houses 3 and 4 or houses 4 and 5 are ivory and green, respectively. Thus house 1 must be yellow. Because of that, the Norwegian owns the Ford (sentence 7) and the horse is kept in house 2 (sentence 11). Thus, our current knowledge is Color yellow blue Drink milk Country Norwegian From here, we can consider two cases, as there are only two possible sequences of colors for houses 3, 4, and 5: Case 1: (ivory, green, red), Case 2: (red, ivory, green). Let's consider these two cases in turn. In case 1, we can infer additional information. The Englishman lives in house 5, as it is red (sentence 1), cocoa is drunk in house 4, because it's green (sentence 3), the Ukrainian drinks eggnog (sentence 4), so he must live in house 2 (as the Norwegian and Englishman live in houses 1 and 5, and milk and cocoa are consumed in houses 3 and 4), the Englishman owns a Mercedes and drinks orange juice (sentence 12, as orange juice is drunk either in house 1 or 5, but the Norwegian from house 1 owns a Ford). Thus, in case 1 our current knowledge is
IX. Who Owns the Zebra? 227 Color yellow blue ivory green red Drink eggnog milk cocoa orange Country Norwegian Ukrainian Englishman Mercedes And now it's clear that this case doesn't lead to a solution! To see this, let's investigate who the owner of the Oldsmobile is? It's not the Norwegian nor the Englishman, as we already know what they own. It is not the Japanese, as sentence 13 says that he drives a Volkswagen. It is not the Ukrainian, as the Oldsmobile owner owns snails (sentence 6) and the Ukrainian owns a horse. And it can't be the Spaniard because he owns a dog (sentence 2). Thus, we've reached a contradiction. In case 1, it's impossible to satisfy the remaining constraints of the problem. Thus, case 2 must hold true. Now we know that the colors of houses 3, 4, and 5 are red, ivory, and green, respectively. Again, sentences 1 and 3 give us additional pieces of certain information and our current knowledge is Drink milk cocoa Country Norwegian Englishman At this stage we can reason as follows. As the Ukrainian drinks eggnog (sentence 4), he must live either in house 2 or 4 (cocoa's drunk in house 5). But if the Ukrainian lives in house 4, then the Spaniard (who owns a dog by sentence 2) must live in house 5, and the Japanese must live in house 2. Also, orange juice must be drunk in house 2 (sentence 12) whose inhabitant drives a Mercedes. This is a contradiction because the Japanese owns a Volkswagen! We conclude then that the Ukrainian must live in house 2 and the current information we have is Drink eggnog milk cocoa Country Norwegian Ukrainian Englishman From this stage it's now easy to find the solution. As the owner of Mercedes Benz drinks orange juice (sentence 12), he must live in house 4. As the Japanese owns a Volkswagen, he must live in house 5. Thus the Spaniard (who also owns a dog) lives in house 4. At this stage we know that
228 IX. Who Owns the Zebra? Drink eggnog milk orange cocoa Country Norwegian Ukrainian Englishman Spaniard Japanese Mercedes Volkswagen dog Sentence 6 says that the Oldsmobile owner also owns snails, so he must live in house 3. Sentence 10 allows us to place the Chevrolet and the fox. It's clear now that the Japanese owns the zebra and the Norwegian drinks water: Drink water eggnog milk orange cocoa Country Norwegian Ukrainian Englishman Spaniard Japanese Chevrolet Oldsmobile Mercedes Volkswagen Pet fox horse snails dog zebra And you thought we'd never get there! Another way of looking at this puzzle is a bit more formal. There are 15 variables of the problem: a; - the color of house i, b;- the drink consumed in house i, c; - the nationality of the person living in house i, d;- the car that's owned by the tenant of house i, and e; - the pet of the tenant of house i. Each of these variables has a domain: dom(a,) = {yellow(y), blue(b), red(r), ivory(!), green( G)}, dom(b,) = {water(w), eggnog( E), milk(m), orangejuice(o), cocoa( C)}, dom(c,) = {Norwegian(N), Ukrainian(U), Englishman(E), Spaniard( S), Japanese( J)}, dom(d;) ={Ford( F), Chevrolet( C), Oldsmobile( D), Mercedes(M), V olkswagen(v)}, and dom(e;) ={fox( F), horse( H), snails(s), dog( D), zebra(z)}. We can represent our knowledge as a table with possible domains for each variable. For example, after analyzing sentences 8, 9, 14, 1, and 5 we know 9 House Color Drink Country Car Pet 1 {Y} {W} {N} {F} {F,Z} 2 {B} {O,E} {U,J} {M, V, C} {H} 3 {R,I} {M} {E,S, J} {0, V,C} 4 {I,G} {C,O,E} {S,U,J} {M,O, V,C} 5 {R,G} {C,O,E} {E, S, U, J} {M,O, V,C} 9Note that by filling the table with the domains of the appropriate variables, we know immediately that the Norwegian drinks water. Finding the owner of zebra is more difficult.
IX. Who Owns the Zebra? 229 The remaining constraints are interpreted as constraints for values of the appropriate variables. For example, sentence 2 becomes if c, = S then ei = D (fori= 2,3,4,5). So the task is to select appropriate values for each attribute (color, drink, country, car, and pet) and each house, so that all of the constraints are satisfied. It's good to practice on constraint satisfaction problems like this because it forces you to think logically, considering what is possible and what is impossible. These problems also seem to show up on graduate school entrance exams, so remember the old boy scout motto: Be prepared! And if you've already finished school, then hey, aren't you glad that's over with?!