1. Cutting Drinks

(Clocksin, Clause and Effect, 4.1)

Consider this program:

drink(milk).
drink(beer) :- !.
drink(whiskey).

What will these queries produce?

  1. drink(X).

  2. drink(X), drink(Y).

  3. drink(X), !, drink(Y).

2. Good Restaurants

(Bratko, 5.4)

Consider this program with information about restaurants:

good(bila_kuzelka).
good(tri_stoleti).
good(kampa_park).
good(zlata_studna).

expensive(kampa_park).
expensive(zlata_studna).

cheap(R) :- \+ expensive(R).

What will these queries produce?

  1. good(X), cheap(X).

  2. cheap(X), good(X).

3. Bidirectional Factorial

Write a predicate factorial(N, F) that is true if F = N! . Your predicate should work in all directions and should terminate when the solution set is finite.

4. Beethoven's Wig

Someone has stolen Beethoven's wig and has put it in one of four locked boxes. The boxes are numbered 1,2,3,4 in that order. There are four different keys that each have their own color. Also:

  1. The green key goes to the third or fourth box.

  2. The wig is to the left of the fourth box.

  3. The wig is to the right of the first box.

  4. The yellow key is to the left of the wig.

  5. The blue key is to the right of the yellow key and to the left of the green key.

  6. The red key goes to the first box.

Which box contains Beethoven's wig? Write a Prolog program that can find the answer.

5. Three Coins

(Levesque, Thinking as Computation, 9.1.1)

Three coins are on a table. Two are heads up, and one is tails up:

H H T

We would like to make exactly N flips so that they all look the same:

H H H
or
T T T

  1. Write a predicate that can generate all solutions where N = 3.

  2. Write a predicate that can generate all possible solutions, in increasing order of N.

6. Wolf, Goat, Cabbage

A farmer is on the south bank of a river with a wolf, a goat, and a cabbage. He has a boat that can hold him plus any one of these three items. If the wolf and goat are left alone without the farmer, the wolf will eat the goat. If the goat and cabbage are left alone without the farmer, the goat will eat the cabbage. The wolf does not like cabbage.

How can the farmer cross with all of these possessions to the north bank? Write a Prolog program that can determine the shortest solution.