1

I have these predicates:

male(roelof).
male(mans). 
male(ronald).
male(jan).

female(chantal).
female(marie).
female(gerda).
female(dagmar).
female(denise).
female(kimberly).


parent(mans,gerda).
parent(mans,roelof).
parent(marie,gerda).
parent(marie,roelof).
parent(dagmar,denise).
parent(dagmar,kimberly).
parent(ronald,denise).
parent(ronald,kimberly).
parent(chantal,tamara).
parent(roelof,tamara).
parent(jan,chantal).
parent(jan,dagmar).

father_child(Father, Child) :-
 parent(Father, Child),
 male(Father).

mother_child(Mother, Child) :-
 parent(Mother, Child),
 female(Mother).

child_father_mother(Child, Father, Mother) :-
 father_child(Father, Child),
 mother_child(Mother, Child).

same_father(Child, Sibling) :-
 father_child(Father, Child),
 father_child(Father, Sibling).

same_mother(Child, Sibling) :-
 mother_child(Mother, Child),
 mother_child(Mother, Sibling).

siblings(X,Y) :-
        (   same_father(X, Y),
        X \= Y
    ;   same_mother(X, Y),
        \+ same_father(X, Y)
    ).

display_siblings(Person) :-
      findall(Person-Y, siblings(Person,Y), Sibs),
       display_the_siblings(Sibs).

display_the_siblings([]) :-
       write('Er zijn geen zussen/broers bekend').

display_the_siblings([X-Y]) :-
        write('The enigste broer of zuster is '),
        write(Y).

display_the_siblings([XY0,XY1|XYs2]) :-
        XYs0=[XY0,XY1|XYs2],
        write('Alle zusterparen zijn : \n '),
        forall(( member(X - Y,XYs0)
       ),( format('~w en ~w. \n',[X,Y])
        )).

It works fine but if you do display_siblings(X) you will see duplicates like this

Person 1 - Person 2

Person 2 - Person 1

How can I change this so the duplicates will not show up. I know I can change findall to setof but then I see no output at all.

Roelof

Edit 1: @< works but it also means that display(kimberly) fails because Kimberly is further on the alphabet then denise. Can I not use the same trick as this topic : How can I prevent duplicates in prolog.

Community
  • 1
  • 1
user3426797
  • 35
  • 1
  • 6

1 Answers1

0

the simplest way should be to break the symmetry, for instance

... 
findall(Person-Y, (siblings(Person,Y), Person @< Y), Sibs),
...
CapelliC
  • 59,646
  • 5
  • 47
  • 90