Decision Intelligence Platform

Rule Solver – Where is Zebra?

Problem Description. There are five houses.

  1. The Englishman lives in the red house.
  2. The Spaniard owns the dog.
  3. Coffee is drunk in the green house.
  4. The Ukrainian drinks tea.
  5. The green house is immediately to the right of the ivory house.
  6. The Old Gold smoker owns snails.
  7. Kools are smoked in the yellow house.
  8. Milk is drunk in the middle house.
  9. The Norwegian lives in the first house.
  10. The man who smokes Chesterfields lives in the house next to the man with the fox.
  11. Kools are smoked in the house next to the house where the horse is kept.
  12. The Lucky Strike smoker drinks orange juice.
  13. The Japanese smokes Parliaments.
  14. The Norwegian lives next to the blue house.

Question: where is Zebra?

 Implementation. Let’s start with a business glossary:

It has five input arrays — Colors, People, Drinks, Pets, and Cigarettes — with the names of their elements. The domain “1-5” directs the Solver to create decision variables with possible values from 1 to 5, specifying the yet-unknown house numbers.

Here are the corresponding test cases:

The table “Define” posts constraints and logs the unknown variables. The table “Solve” calls the predefined method “SolverFindSolution:

Here are all constraints:

After a double-click on “test.bat”, we will receive the following results:

  • Green[5] Ivory[4] Blue[2] Red[3] Yellow[1]
  • Norwegian[1] Ukrainian[2] Japanese[5] Englishman[3] Spaniard[4]
  • Juice[4] Tea[2] Milk[3] Water[1] Coffee[5]
  • Snail[3] Dog[4] Fox[1] Horse[2] ZEBRA[5]
  • Chesterfield[2] Parliament[5] Lucky[4] OldGolds[3] Kools[1]

Thus, Zebra lives in House #5.