

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solutions to prolog exercises covering family relationships and list processing. Topics include defining predicates for parent-child relationships, siblings, grandchildren, first cousins, descendants, and list processing functions such as third element, first pair, deleting the third element, checking for duplicate elements, odd and even list sizes, and list prefixes and membership.
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


mother(X,Y) :- female(X), parent(X,Y).
father(X,Y) :- male(X), parent(X,Y).
sibling(X,Y) :- parent(Z,X), parent(Z,Y), not(X=Y). sister(X,Y) :- female(X), sibling(X,Y).
grandson(X,Y) :- male(X), parent(Y,Z), parent(Z,X).
firstCousin(Cousin1,Cousin2) :- parent(Parent1,Cousin1), parent(Parent2,Cousin2), sibling(Parent1,Parent2).
descendant(Desc,Ances) :- parent(Ances,Desc). descendant(Desc,Ances) :-
parent(Ances,X), descendant(Desc,X).
third([,,Y|_],Y).
firstPair([X,X|_]).
del3([A,B,_|Rest],[A,B|Rest]).
isDuped(Y) :- dupList(_,Y).
oddSize([]). oddSize([,_|Rest]) :- oddSize(Rest).
evenSize([]). evenSize([,|Z]) :- evenSize(Z).
prefix(X,Y):- append(X,_,Y).
isMember(X,[X|]). isMember(X,[|Z]) :- isMember(X, Z).
isUnion([],Y,Y). isUnion([H|T],Y,Z) :-