You should say "a succeeds only if b, c and d (so e) succeed".
Since b, c and e are facts, a succeeds.
Yes, every letter in this example can be a goal.
You must have facts, e.g. percentage of troubles when there is a cranky husband or a demanding wife.
These facts may be converted in rules, so you have to search for "expert system".
I can't edit my posts so, I give you another way to count nodes in DFS without assert/retract :
dfs_search_node(Tree,Node, N) :-
dfs_search_node_(Tree,Node, 1, _, N).
dfs_search_node_(tree(Node, _, _), Node, FN, _, FN) :- !.
dfs_search_node_(tree(_, L, R), Node, CN, _TN, FN) :-
CN1 is CN +...
If I understand what you mean, for 6 it should 10 :
6 is not 1 : step 1
then I search in left tree
6 is not 2 : step 2
I search in left tree
6 is not 3 : step 3
I search in left tree
tree empty : step 4
I search in right tree
tree empty : step 5
.....
According to this scheme I propose :
:-...
Well here is my code, works with SWI-Prolog
child_of(name1,name0).
child_of(name2,name1).
child_of(name3,name2).
descendent(X,Y) :-
child_of(X,Y).
descendent(X,Y) :-
child_of(Z,Y),
descendent(X,Z).
If I use descendent(X,Y) :-
descendent(X,Z),
child_of(Z,Y).
at the query descendent(name1...
The design for descendent/2, is almost good : try descendent(name1, name0) and after the answer true type ";" instead of Enter, you will enter an infinite loop !
After having fixed the bug, try the same design for descendent/3.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.