Define graph in Prolog: edge and path, finding if there is a path between two vertices
Cycles in the graph. You need to track what nodes you’re visiting, and check them. Try this, using a helper predicate with an accumulator to track the visited nodes: path(A,B) :- % two nodes are connected, if walk(A,B,[]) % – if we can walk from one to the other, . % first seeding the visited … Read more