Skip to content

Instantly share code, notes, and snippets.

@reverendpaco
Last active October 19, 2018 18:06
Show Gist options
  • Save reverendpaco/bf342ced3ca8447180d8df2c9bef6880 to your computer and use it in GitHub Desktop.
Save reverendpaco/bf342ced3ca8447180d8df2c9bef6880 to your computer and use it in GitHub Desktop.
male(terah).
male(abraham).
male(nahor).
male(haran).
male(isaac).
male(ismael).
male(jacob).
female(sarah).
female(hagar).
father(terah, sarah).
father(terah, abraham).
father(abraham, isaac).
father(isaac, jacob).
father(abraham, ismael).
mother(sarah,isaac).
mother(hagar,ismael).
parent(Parent,Child) :- father(Parent,Child).
parent(Parent,Child) :- mother(Parent,Child).
son_of(Child,Parent) :-
male(Child), parent(Parent,Child).
daughter_of(Child,Parent) :-
female(Child), parent(Parent,Child).
grandparent_of(GrandChild,GrandParent) :-
distinct( (GrandParent,GrandChild),
(parent(GrandParent,Someone),parent(Someone,GrandChild)) ).
ancestor_of(Descendant,Ancestor) :-
distinct( (Ancestor,Descendant),parent(Ancestor,Descendant)).
ancestor_of(Descendant,Ancestor) :-
distinct((Ancestor,Descendant),
(parent(Ancestor,X), ancestor_of(Descendant,X))).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment