Table of Contents

Opis

Predikat sister(X, Y) velja natanko takrat, kadar je X sestra od Y. Primer klica:

?- sister(X, patricia).
  X = vanessa.

Predznanje

Povezave so podane s predikatom parent/2. Predikata male/1 in female/1 določata spol vsake osebe (vozlišča).

parent(tina,william).                      male(william).
parent(thomas,william).                    male(thomas).
parent(thomas,sally).                      male(jeffrey).
parent(thomas,jeffrey).                    male(andrew).
parent(sally,andrew).                      male(steve).
parent(sally,melanie).                     male(patrick).
parent(andrew,joanne).                     male(john).
parent(jill,joanne).                       male(michael).
parent(joanne,steve).                      male(frank).
parent(william,vanessa).                   male(george).
parent(william,patricia).                  male(morty).
parent(vanessa,susan).                     male(jerry).
parent(patrick,susan).                     male(kramer).
parent(patricia,john).                     male(aleksandr).
parent(john,michael).                      male(alessandro).
parent(john,michelle).                     male(aleksander).

parent(frank,george).                      female(tina).
parent(estelle,george).                    female(sally).
parent(morty,jerry).                       female(melanie).
parent(helen,jerry).                       female(joanne).
parent(jerry,anna).                        female(jill).
parent(elaine,anna).                       female(vanessa).
parent(elaine,kramer).                     female(patricia).
parent(george,kramer).                     female(susan).
                                           female(michelle).
parent(margaret,nevia).                    female(estelle).
parent(margaret,alessandro).               female(helen).
parent(ana,aleksander).                    female(elaine).
parent(aleksandr,aleksander).              female(anna).
parent(nevia,luana).                       female(margaret).
parent(aleksander,luana).                  female(ana).
parent(nevia,daniela).                     female(nevia).
parent(aleksander,daniela).                female(luana).
                                           female(daniela).

Rešitev

sister(X, Y) :-
    parent(Z, X),
    parent(Z, Y),
    female(X),
    X \== Y.

Namigi

# Namig
1 X in Y morata imeti (vsaj enega) skupnega starša.
2 X mora biti ženskega spola.
3 X ne more biti sestra sama sebi.
4 Y ni nujno ženskega spola / relacija ni simetrična.

Testni primeri

ex(sister(sally, william)).        nex(sister(william, jeffrey)).
ex(sister(melanie, andrew)).       nex(sister(tina, thomas)).
ex(sister(luana, daniela)).        nex(sister(nevia, aleksander)).
ex(sister(daniela, luana)).        nex(sister(joanne, jill)).

#1

nex(sister(vanessa, andrew)).
nex(sister(elaine, george)).
nex(sister(sally, thomas)).

#2

nex(sister(andrew, melanie)).
nex(sister(patrick, vanessa)).
nex(sister(michael, michelle)).

#3

nex(sister(vanessa, vanessa)).
nex(sister(sally, sally)).
nex(sister(daniela, daniela)).