I need to implement a tree:
Code
male(Peter).
male(Stewie).
male(Chris).
male(Francis).
male(Joe).
male(Kevin).
female(Louis).
female(Meg).
female(Thelma).
female(Bonnie).
female(Susie).
father(Peter,Stewie).
father(Peter,Chris).
father(Peter,Meg).
father(Joe,Kevin).
father(Joe,Susie).
father(Francis,Peter).
father(Francis,Joe).
mother(Louis,Stewie).
mother(Louis,Chris).
mother(Louis,Meg).
mother(Thelma,Peter).
mother(Bonnie,Kevin).
mother(Bonnie,Susie).
brother(X,Y) :- mother(Z,X),
mother(Z,Y),
male(X),
X \= Y.
sister(X,Y) :- mother(Z,X),
mother(Z,Y),
female(X),
X \= Y.
grandfather(X,Y) :- father(Z,Y); mother(Z,Y),
father(X,Z),
male(X).
grandmother(X,Y) :- father(Z,Y); mother(Z,Y),
mother(X,Z),
female(X).
uncle(X,Y) :- brother(X,Z),
father(Z,Y); mother(Z,Y),
male(X).
aunt(X,Y) :- sister(X,Z),
father(Z,Y); mother(Z,Y),
female(X).
cousin(X,Y) :- father(Z,X); mother(Z,X),
father(Q,Y); mother(Q,Y),
brother(Z,Q); sister(Z,Q).
nephew(X,Y) :- father(Z,X); mother(Z,X),
brother(X,Y); sister(X,Y).
related(X,Y) :- uncle(X,Y); uncle(Y,X);
aunt(X,Y); aunt(Y,X);
brother(X,Y); brother(Y,X);
sister(X,Y); sister(Y,X);
cousin(X,Y); cousin(Y,X);
nephew(X,Y); nephew(Y,X);
mother(X,Y); mother(Y,X);
father(X,Y); father(Y,X);
grandmother(X,Y); grandmother(Y,X);
grandfather(X,Y); grandfather(Y,X).
Everything gives true for some reason xD any idea?
/e Note that I learned prolog in less than a day after learning haskell after 2 classes O.o
This post was edited by IsraeliSoldier on Jul 12 2012 07:17pm