Note: You probably won't get through all of these in one hour. That's ok, but the ones you don't finish, try doing them in your own time and see if you can work them out before we publish the solutions next week.
female(pam). female(liz). female(pat). female(ann). male(tom). male(bob). male(jim). parent(pam, bob). parent(tom, bob). parent(tom, liz). parent(bob, ann). parent(bob, pat). parent(pat, jim). mother(Parent, Child) :- parent(Parent, Child), female(Parent). father(Parent, Child) :- parent(Parent, Child), male(Parent). grandparent(X, Z) :- parent(X, Y), parent(Y, Z). sister(Sister, Sibling) :- parent(P, Sister), parent(P, Sibling), female(Sister), Sister \= Sibling.Define the ancestor relation such that ancestor(X, Y) is true if X is an ancestor of Y. What is the expected output of the query:
ancestor(pam, X).
insert(2, [1, 3], [1, 2, 3]). insert(1, [], [1]).
isort([4, 7, 2, 1], [1, 2, 4, 7]). isort([], []).
?- split([1,2,3,4,5], X, Y). X = [1, 3, 5], Y = [2, 4]
?- merge([1, 5, 6, 9], [2, 5, 11], X). X = [1, 2, 5, 5, 6, 9, 11]
Write a predicate
mergesort(List, SortedList)
which has the same functionality as the
isort/2
predicate from part 2 above, but uses the MergeSort algorithm. Hint: you will need to use the
split/3
and
merge/3
predicates from parts 3 and 4 above.
Resource created Saturday 06 February 2021, 09:11:00 PM, last modified Monday 22 February 2021, 02:09:08 PM.