Hi Gurvan,

path(From, To, [From, To]) :- rel(From, To).
path(From, To, [From | Tail]) :-
   rel(From, Intermediate),
   path(Intermediate, To, Tail).

 How would you prevent an element to appear twice in the path?

You need to keep track of the nodes that you've visited already. Then you check that the Intermediate given by rel/2 is not in the set of already visited nodes.


--
TOK


_______________________________________________
Users-prolog mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/users-prolog

Reply via email to