Skip to content

Instantly share code, notes, and snippets.

@ratulotron
Last active June 10, 2016 16:13
Show Gist options
  • Save ratulotron/c4763a9a9b64281c5144 to your computer and use it in GitHub Desktop.
Save ratulotron/c4763a9a9b64281c5144 to your computer and use it in GitHub Desktop.
Family tree in Prolog
female(pam).
female(liz).
female(pat).
female(ann).
male(tom).
male(bob).
male(jim).
parent(pam, bob).
parent(tom, bob).
parent(tom, liz).
parent(bob, ann).
parent(bob, pat).
parent(pat, jim).
grandparent(X, Z) :-
parent(X, Y),
parent(Y, Z).
same_parent(X, Y) :-
parent(Z, X),
parent(Z, Y),
X \= Y.
has_child(X) :-
parent(X, _).
offspring(X, Y) :-
parent(X, Y).
mother(X, Y) :-
parent(X,Y),
female(X).
sister(X, Y) :-
same_parent(X, Y),
female(X).
happy(X) :-
has_child(X).
hastwochildren(X) :-
parent(X, Y),
sister(Y,_).
grandchild(X, Z) :-
parent(Y, X),
parent(Z, Y).
aunt(X,Y) :-
parent(Z,Y),
sister(X,Z).
predecessor(X, Z) :-
parent(X, Z).
predecessor(X, Z) :-
parent(X, Y),
predecessor(Y, Z).
/**
greater(N,M):-
N > M,
write(N),write(' is greater').
greater(N,M):-
N < M,
write(M),
write(' is greater.').
greater(N,M):-
N == M,
write(M),
write(' and '),
write(N),
write(' are equal.').
reader(X) :-
write('please type animal name:'),
nl,
read(X),
write(X).
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment