Skip to content

Instantly share code, notes, and snippets.

@adrianwong
Created September 15, 2018 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianwong/93f002ab44bfd92242a7232521e5b083 to your computer and use it in GitHub Desktop.
Save adrianwong/93f002ab44bfd92242a7232521e5b083 to your computer and use it in GitHub Desktop.
SWI-Prolog proof to "I'm My Own Grandpa"
husband(me, pretty_widow).
husband(my_dad, pretty_widow_daughter).
wife(X, Y) :- husband(Y, X).
father(me, bouncing_baby_boy).
father(my_dad, me).
father(my_dad, my_dad_new_son).
mother(pretty_widow, bouncing_baby_boy).
mother(pretty_widow, pretty_widow_daughter).
mother(pretty_widow_daughter, my_dad_new_son).
married(X, Y) :- husband(X, Y).
married(X, Y) :- wife(X, Y).
parent(X, Y) :- parent0(X, Y).
parent(X, Y) :- step_parent(X, Y).
step_parent(X, Z) :-
married(X, Y),
parent0(Y, Z),
\+ parent0(X, Z).
parent_in_law(X, Z) :-
married(Y, Z),
parent(X, Y),
\+ parent(X, Z).
parent0(X, Y) :- father(X, Y).
parent0(X, Y) :- mother(X, Y).
grandparent(X, Z) :-
parent(X, Y),
parent(Y, Z).
sibling(X, Y) :- distinct(sibling0(X, Y)).
sibling_in_law(X, Y) :- sibling_in_law0(X, Y).
sibling_in_law(X, Y) :- sibling_in_law0(Y, X).
sibling_in_law0(X, Z) :-
married(X, Y),
sibling(Y, Z).
sibling0(X, Y) :-
parent(Z, X),
parent(Z, Y),
X \= Y.
uncle_aunt(X, Z) :-
sibling(X, Y),
parent(Y, Z).
@sepbot
Copy link

sepbot commented Oct 1, 2018

Congrats Adrian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment