Created
June 13, 2012 02:47
-
-
Save alexandrebini/2921506 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Facts | |
parent(dirce, gislene). | |
parent(dirce, irair). | |
parent(valdemar, gislene). | |
parent(valdemar, irair). | |
parent(gislene, alexandre). | |
parent(gislene, fakebrother). | |
parent(irair, fernando). | |
% Rules | |
child(X, Y) :- parent(Y, X), X\=Y. | |
grandchild(X, Y) :- parent(Z, X), parent(Y, Z), X\=Y. | |
sibling(X, Y) :- parent(Z, X), parent(Z, Y), X\=Y. | |
nephew(X, Y) :- parent(W, X), sibling(W, Y), X\=Y. | |
cousin(X, Y) :- parent(W, X), sibling(W, Z), child(Y, Z), X\=Y. | |
% Queries | |
?- child(alexandre, A), | |
write('Alexandre é filho de '), writeln(A). | |
?- grandchild(alexandre, A), | |
write('Alexandre é neto de '), writeln(A). | |
?- sibling(alexandre, A), | |
write('Alexandre é irmão de '), writeln(A). | |
?- nephew(alexandre, A), | |
write('Alexandre é sobrinho de '), writeln(A). | |
?- cousin(alexandre, A), | |
write('Alexandre é primo de '), writeln(A). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment