Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- child(john,sue). child(john,sam).
- child(jane,sue). child(jane,sam).
- child(sue,george). child(sue,gina).
- child(jeff,george). child(jeff,martha).
- child(fred,jane). child(fred,joe).
- child(britt,john). child(britt,beth).
- child(frank,britt). child(frank,brandon).
- child(katie,fred). child(katie,morgan).
- child(bill,jeff). child(bill,nora).
- child(beth,matt). child(beth,ann).
- child(joe,matt). child(joe,ann).
- child(harry,frank). child(harry,felicity).
- male(john). male(sam). male(george). male(fred).
- male(joe). male(frank). male(brandon). male(jeff).
- male(bill). male(matt). male(harry).
- female(sue). female(jane). female(june). female(martha).
- female(gina). female(britt). female(beth). female(katie).
- female(morgan). female(nora). female(ann). female(felicity).
- parent(Y,X) :- child(X,Y).
- father(Y,X) :- child(X,Y), male(Y).
- opp_sex(X,Y) :- male(X), female(Y).
- opp_sex(Y,X) :- male(X), female(Y).
- grand_father(X,Z) :- father(X,Y), parent(Y,Z).
- mother(Y,X) :- child(X,Y), female(Y).
- grand_parent(X,Z) :- parent(X,Y), parent(Y,Z).
- great_grand_mother(X,Z) :- mother(X,W), parent(W,Y), parent(Y,Z).
- sibling(X,Y) :- parent(Z,X), parent(Z,Y), \+ X=Y.
- brother(X,Y) :- sibling(X,Y), male(X). %X is a brother of Y
- sister(X,Y) :- sibling(X,Y), female(X). %X is a sister of Y
- half_sibling(X,Y) :- sibling(X,Y), parent(Z,X), parent(A,Y), parent(B,X), parent(C,Y), \+ A=Z, \+ B=C, \+ A=B, \+Z=B.
- full_sibling(X,Y) :- sibling(X,Y), parent(Z,X), parent(Z,Y), parent(A,X), parent(A,Y), \+ A=Z.
- first_cousin(X,Y) :- parent(Z,X), parent(A,Y), sibling(A,Z), \+A=Z.
- second_cousin(X,Y) :- parent(Z,X), parent(A,Y), first_cousin(A,Z), \+A=Z.
- half_first_cousin(X,Y) :- parent(Z,X), parent(A,Y), half_sibling(A,Z), \+A=Z.
- double_first_cousin(X,Y) :- parent(Z,X), parent(A,Y), parent(B,X), parent(C,Y), sibling(A,Z), sibling(B,C), \+Z=A, \+B=C, \+Z=B, \+A=B.
- first_cousin_twice_removed(X,Y) :- grand_parent(Z,X), first_cousin(Z,Y),\+ half_first_cousin(Z,Y).
- first_cousin_twice_removed(X,Y) :- first_cousin_twice_removed(Y,X).
- descendant(X,Y) :- child(X,Y).
- descendant(X,Y) :- child(X,Z), descendant(Z,Y), \+ Y=Z.
- ancestor(X,Y) :- descendant(Y,X).
- cousin(X,Y) :- parent(Z,X), parent(A,Y), sibling(Z,A), \+A=Z.
- cousin(X,Y) :- parent(Z,X), parent(A,Y), cousin(Z,A), \+A=Z.
- closest_common_ancestor(X,Y,Z) :- ancestor(X,Y), ancestor(X,Z), child(A,X), \+ancestor(A,X), \+ ancestor(A,Y), \+A=X, \+ Y=Z.
- write_child(X,Y) :- write(X), write(' is a child of '), write(Y), nl.
- write_descendant_chain(X,Y) :- child(X,Y), write_child(X,Y).
- write_descendant_chain(X,Y) :- child(X,Z), \+ Y=Z, write_child(X,Z), write_descendant_chain(Z,Y).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement