Skip to content

Instantly share code, notes, and snippets.

@draftcode
Created December 16, 2011 06:43
Show Gist options
  • Select an option

  • Save draftcode/1484835 to your computer and use it in GitHub Desktop.

Select an option

Save draftcode/1484835 to your computer and use it in GitHub Desktop.
father(naoyuki, hyogo).
father(saburo, naoyuki).
father(saburo, shinji).
father(yoshihisa, hisako).
mother(hisako, hyogo).
mother(yoko, naoyuki).
mother(yoko, shinji).
mother(nobuko, hisako).
parent(P, C) :- father(P, C).
parent(P, C) :- mother(P, C).
grandfather(GF, C) :- parent(P, C), father(GF, P).
grandmother(GF, C) :- parent(P, C), mother(GF, P).
grandparent(GP, C) :- grandfather(GP, C).
grandparent(GP, C) :- grandmother(GP, C).
child(C, P) :- parent(P, C).
grandchild(C, G) :- grandparent(G, C).
sibling(X, Y) :- parent(P, X), parent(P, Y).
son(S, P) :- parent(P, S).
uncle(U, C) :- parent(P, C), brother(P, U), not(P = U).
ancestor(A, C) :- parent(A, C).
ancestor(A, C) :- parent(P, C), ancestor(A, P).
descendant(D, P) :- child(D, P).
descendant(D, P) :- child(C, P), descendant(D, C).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment