Program Assignment 3

## 100 Points Due: 11/14/01 at the start of class

 Problem

This is your first assignment in Prolog, and is intended to demonstrate a capability in the language that is difficult to implement in any other language.

Design, implement and fully test, a Prolog program that will solve the following logic problem:

There are 5 houses, each of a different color and inhabited by a man of a different nationality, with a different pet, drink, and dessert choice. From the clues given below, determine which person lives in which house, what kind of pet they own, what their favorite drink is, and what their favorite dessert is.

The complete set of data for this puzzle is:

 House Colors: blue green ivory red yellow Nationalities: Englishman Japanese Norwegian Spaniard Ukrainian Pets: dog fox horse snails zebra Drinks: Coffee milk orange juice tea water Desserts: ice cream pie cake chocolate mousse

The clues you have available are:

• 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 to the immediate right of the ivory house.

• The ice cream eater owns snails.

• Pie is preferred in the yellow house.

• Milk is drunk in the middle house.

• The Norwegian lives in the first house on the left.

• The cake lover lives next to the man with the fox.

• Cake is preferred in the house adjacent to the horse's place.

• The chocolate lover drinks orange juice.

• The Japanese man loves mousse.

• The Norwegian lives next to the blue house.

• The Englishman owns the fox.

For this program, there is no interactive input data. Further, your program must produce a solution within 1 minute of execution time.

 Implementation Language

For this assignment, your program must be written in Prolog. You will be programming in a "logic programming" style, as described in Chapter 15 of the text book. Since this program must be written in Prolog, appropriate use of logic programming language features is expected. In particular, you may not use any versions of assert, retract, record, erase, flag, or any of the other database features of Prolog.

As with prior programs, your solution must adhere to good programming style, including correct use of parameter passing, identifier naming, predicate length, commenting, headers for each predicate, etc.

 Input/Output Format

Write your program as a prolog predicate called house_solution taking 20 unbound variables as parameters, like this:

house_solution(
Blue_Nationality,   Blue_Pet,   Blue_Drink,   Blue_Dessert,
Green_Nationality,  Green_Pet,  Green_Drink,  Green_Dessert,
Ivory_Nationality,  Ivory_Pet,  Ivory_Drink,  Ivory_Dessert,
Red_Nationality,    Red_Pet,    Red_Drink,    Red_Dessert,
Yellow_Nationality, Yellow_Pet, Yellow_Drink, Yellow_Dessert
) :-  /* your implementation here */
...
The Curator will invoke your solution with 20 unbound variables and then print out the results using write goals.