Assignment 5

1. Write the Prolog code for the following predicate using an accumulator:
nth( N, List, Term).    in which List is an instantiated list and N is instantiated to an integer. The predicate instantiates Term to the Nth element of List. Provide a few examples that test your predicate.

2. Complete the clause for p below. The clause instantiates SetX to the elements of Set1 that do not appear in Set2. For example,

?- p([ r1(500), r2(500), a, [1,2]], [a, [1,2]],X).

X = [r1(500),r2(500)]

You can use any of the library predicates that have been discussed in class.

p( Set1, Set2, SetX ) :-