Kirdneh
Programmer
- Jan 19, 2013
- 2
Hi,
I am learning prolog and I am not able to fullfill the following excercise:
1. I have a list of facts:
f(name0).
m(name1).
-> these are persons, f(x) means female, m(x) means male.
child_of(x,y).
-->x is a child of y.
2. I want to now if x is and descendent of y:
descendent(x,y) :- child_of(x,y).
descendent(x,y) :- descendent(x,z), child_of(z,y).
3. so far everything worked fine, but here is my problem:
I want to have a request descendent(x, y, z) which means that
x is a descendent of y and z is the realtion between them.
so if I am requesting:
?- descendent(person1, person2, X).
X = c(person2).
Which means person1 is a child of person 2.
or
?- descendent(person3, person4, X).
X = c(c(person4)).
Which means person 3 is a child of a child of person4.
How can I code that? Any hints would be a pleasure.
I am learning prolog and I am not able to fullfill the following excercise:
1. I have a list of facts:
f(name0).
m(name1).
-> these are persons, f(x) means female, m(x) means male.
child_of(x,y).
-->x is a child of y.
2. I want to now if x is and descendent of y:
descendent(x,y) :- child_of(x,y).
descendent(x,y) :- descendent(x,z), child_of(z,y).
3. so far everything worked fine, but here is my problem:
I want to have a request descendent(x, y, z) which means that
x is a descendent of y and z is the realtion between them.
so if I am requesting:
?- descendent(person1, person2, X).
X = c(person2).
Which means person1 is a child of person 2.
or
?- descendent(person3, person4, X).
X = c(c(person4)).
Which means person 3 is a child of a child of person4.
How can I code that? Any hints would be a pleasure.