Prolog

You are to solve the following two problems in Prolog. You may want to use solutions to the Factorial problem and the Cannibals and Priests problem as a guide.

Towers of Hanoi

You are given three poles (labeled A, B, and C) attached to a baseboard, and a number (N, the input to your program) of wooden disks. Each disk has a hole in the middle large enough to fit the disk on the pole; the disks all have different diameters.

Initially, all the disks are on pole A, with the largest disk on the bottom, and no disk above a smaller one.

The problem is to move the tower of disks, one disk at a time, from pole A to pole C, using pole B for intermediate moves as necessary. At no time may a disk be placed above a smaller disk.

Your program should print out each move used to reach a successful conclusion.

This is an ancient puzzle with an associated myth. The myth is that somewhere in the world there are priests actually solving the puzzle, moving 20 physical disks one at a time, taking one minute for each move. The world will end when they finish the task. How long do we have?

Farmer's Problem

A farmer, on his way to market, is carrying a fox, a chicken, and a sack of grain. He must cross a river using a boat that can only take the farmer and at most one other thing.

The farmer cannot leave the fox alone with the chicken, or the chicken alone with the grain. (In one case the fox eats the chicken, in the other case the chicken eats the grain.)

Find a series of crossings by the farmer that results in everything arriving on the far side of the river intact.

What to Turn In

You must turn in a source code listing of your Prolog program, and the output of an execution. You should also identify the directory where the source code resides.

Due Date

This assignment is due Thurs, April 22.