Question

Assume that the following facts are already entered into the Prolog database:

father(X, Y)     // X is the father of Y
mother(X, Y)     // X is the mother of Y
male(X)          // X is a male
female(X)        // X is a female
parent(X, Y)     // X is a parent of Y
diff(X, Y)       // X and Y are different

(1) Now add a Prolog rule for grandpa_of(X, Y) where "X is the grandfather of Y"

(2) Add another rule for sibling(X, Y) where "X is the sibling of Y"

My thoughts:

Question 1:

I am confused on how I can find the parents of the parents, all I have so far is

grandpa_of(X,Y) :- male(X), ...

Question 2:

sibling(X, Y) :- parent(P, X), parent(P, Y), diff(X, Y)

Was it helpful?

Solution

I think Jason means grandpa_of(X,Y) :- father(X,P), parent(P,Y).

OTHER TIPS

It has been a long time... The first one is something like this:

grandpa_of(X, Y) :- father(X, P), father(P, Y).

Been too long... :-P

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top