このディレクトリの索引

# 
# I'm terrible with prolog. I keep getting a duplicate result in this simple code"
# 
# mates(bob, john).
# mates(bob, bill).
# mates(andrea, sara).
# mates(andrea, bill).
# friends(X, Y) :- mates(X, Z), mates(Y, Z).
# Calling friends(bob, X). I get bob twice. If only I could use and IF statement argh!!!
# 
# How can I elimiate duplicate results? IE If(result1 == result2) dont print;
# 
# Im looking for similar friends, ie the result should be bob and andrea (because of bill).
# 

mates(bob, john).
mates(bob, bill).
mates(andrea, sara).
mates(andrea, bill).

friends(X, Y) :-
        setof([X,Y],(friends2(X,Y),\+(X=Y)),L),
        append(L0,[[X,Y]|_],L),
        \+(append(_,[[Y,X]|_],L0)).

friends2(X, Y) :- mates(X, Z), mates(Y, Z).
friends2(X, Y) :- mates(X, Z), mates(Z, Y).
friends2(X, Y) :- mates(Z, X), mates(Z, Y).
friends2(X, Y) :- mates(Z, X), mates(Y, Z).