Assignment 5

  1. Give a tail-recursive definition for each of the following predicates.

  2. Write a program to generate all perfect numbers between 1 and 100. A perfect number is a positive integer that is equal to the sum of its proper divisors. For example, 6(=1+2+3) is a perfect number.

  3. Write a program in Prolog to solve the following maze.

                           

  4. Write a program in Prolog to solve the crossword puzzle (Problem C) in the problem set used in the 1999 ACM programming contest. For the sake of simplicity, you only need to write a predicate, called puzzle(Slots,Words), to solve one case where the available slots and words are given as lists. For example, to solve the sample problem, the call should be puzzle([[1,1,d],[2,3,d],[3,1,a],[5,2,a]],[[s,l,o,w],[a,g,a,i,n],[b,o,y],[t,a,i,l],[b,e,a,r]]).