Question

I'm wondering how would I be able to call a nephew or niece in a family tree without using a sibling fact for prolog. I can't figure out a way to do it by calling the uncle directly.

For example:

parent(elli, lisa).
parent(kelly, lisa).

parent(ben, claire).
parent(lisa, claire).

grandparent(X, Y) :- parent(X, Z), parent(Z, Y).

Since ellie or kelly is ben's niece, I have the rule that when called by grandparent(X, claire). will give elli and kelly as the grandchild of claire. How would I make a rule to be able to call niece(ben, X). so it'll list all of ben's niece. I can't figure out a way to do it with only the parent fact, the only way of doing it would be to include a sibling fact but is there a way to do it without making a sibling fact?

I'm very new to prolog, literally like a week ago so please excuse me if I don't understand it that well.

Was it helpful?

Solution

brother(X, Y) :- male(X), parent(X, Z), parent(Y, Z), X \= Y.

uncle(X, Y) :- brother(X, Z), parent(Y, Z).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top