I'm given a list of arcs:
arc(a,b).
arc(b,c).
arc(c,d).
arc(d,b).
arc(d,e).
arc(e,e).
arc(e,f).
I've written a set of clauses which will tell me if theres a path from node X to node Y. Loops may occur and I've accounted for that.
path(X,Y) :- arc(X,Y).
path(X,Y) :-
arc(X,Z),
path(Z,Y,[X]).
path(X,Y,P) :- arc(X,Y).
path(X,Y,P) :-
\+member(X,P),
arc(X,Z),
append([X],P,L),
path(Z,Y,L).
I need to modify this to, on success, return a list of nodes that were traversed. I'm unclear as to how I would do this. I assume my base case would be something like path2(X,Y,[X,Y]) :-
arc(X,Y).
but that won't work with my program. Is there something wrong with my solution for the previous part, or am I just missing a small modification? Any help would be appreciated. Thanks!