Homework # 9
due Thursday, May 17, 2:00 PM

Simple Prolog Programs

Solve Exercises 10,11 on page 415. Also define a predicate mingle that takes three arguments and returns true if the third can be created by mingling the elements of the first two together while preserving relative order:

?- mingle([1,2],[3],[3,1,2]).
Yes
?- mingle([1,2],[3],[1,3,2]).
Yes
?- mingle([1,2],[3],[3,2,1]).
No
?- mingle(X,Y,[1,2]).

X = [1, 2]
Y = [] ;

X = [1, 2]
Y = [] ;

X = [1, 2]
Y = [] ;

X = [1]
Y = [2] ;

X = [2]
Y = [1] ;

X = [2]
Y = [1] ;

X = []
Y = [1, 2] ;

No
As this example shows, it is permitted to yield the same results more than once. Also, you can assume that either the first or the last argument is a fixed length list.

Searching

On paper, do Exercises 1 and 2 on page 446.

Ungraded!

For fun, you might want to do Exercise 6 on page 447. This part is optional and ungraded.


About this document



John Boyland 2007-05-24