parent(b, a).
parent(c, a).
parent(d, a).
parent(e, b).
parent(f, b).
parent(h, d).
parent(i, d).
parent(j, d).
parent(k, d).
child(X, Y) :-
parent(Y, X).
grandparent(X, Y) :-
parent(X, Z),
parent(Z, Y).
grandchild(X, Y) :-
child(X, Z),
child(Z, Y).
sibling(X, Y) :-
parent(X, Z),
parent(Y, Z),
X\=Y.
auncle(X, Y) :-
parent(X, Z),
sibling(Z, Y).
cousin(X, Y) :-
auncle(X, Z),
child(Y, Z).
happy(X) :-
not(parent(Y,X)).
Prolog problem
[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]
You should be able to do findall(Person, happy(Person), ListOfHappyPeople).
apparently the answer was:
happy(X) :-
parent(X, _),
not(parent(_, X)).
happy(X) :-
parent(X, _),
not(parent(_, X)).
[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement