Solve Exercises 1,2,3 on page 414. Define a predicate
related(X,Y) that is true if X and Y are blood
relatives according to the known facts. Using the examples on page
389, holly and jean are related, but esther and
herbert are not related. Everyone is related to himself or herself.
Put all the answers in
family.pl. Put sample parent, male, and female
facts in a separate file relations.pl.
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] ; NoAs 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. The code for
mingle as well
as the answers to Exercises 10 and 11 should go into sequence.pl.
On paper, do Exercises 1 and 2 on page 446.
For fun, you might want to do Exercise 6 on page 447. This part is optional and ungraded.
You submit your program work by putting it in the homework10 directory
in your AFS class volume.
You may do all your work in this directory, or you may wish to do your
work in a different directory and copy things when correct into this
directory. In any case, you will lose permission to write things in
this directory after the deadline, which is 4:00pm on Tuesday,
April 20th. In other words, you must be done before lecture
starts.
The homework10 directory should include the following:
P.S. The command to start the SWI-Prolog interpreter on the grids is
pl.