Family tree - cousin relationships with repeated names

779 Views Asked by At

I am trying to get my cousin relationship to work accurately. For example when I do the query: cousins(X,ron). It returns: X = nancy;X = nancy;X = jeff;X = jeff;X = david;X = thomas. I believe these are the correct cousins but I don't want to return a name more than once. How can I fix this? And this is the one relationship that is difficult for me to decipher if these are actually cousins or not.

parent(A,B) :- mother(A,B); father(A,B).
grandparent(C,E) :- parent(C,D),parent(D,E).
grandmother(C,E) :- mother(C,D),parent(D,E).
grandfather(C,E) :- father(C,D),parent(D,E).
siblings(B,G) :- parent(P,B), parent(P,G), B\=G.
cousins(X,Y) :- parent(A,X), parent(B,Y), siblings(A,B), X\=Y.

mother(mary,sue).
mother(mary,bill).
mother(sue,nancy).
mother(sue,jeff).
mother(jane,ron).
mother(nancy,alice2).
mother(gail,jane).
mother(gail,elaine).
mother(laura,alice).
mother(elaine,david).
mother(sarah,frank).
mother(elaine,thomas).

father(john,sue).
father(john,bill).
father(bob,nancy).
father(bob,jeff).
father(bill,ron).
father(charlie,alice2).
father(david,charlie).
father(carl,jane).
father(peter,laura).
father(frank,thomas).
father(frank,david).
father(thomas,alice).
father(henry,frank).

(ancestor(A,D):-parent(A,D)).
(ancestor(A,D):-(parent(P,D),ancestor(A,P))).
0

There are 0 best solutions below