0

I am a real newbie in Prolog and I am having a hard time with some basic stuff...

I have a cluster of letters connected to each other randomly. Each letter is a node and the connection between two letters is an edge. I'm trying to find the path between a letter to another. E.g : the path between A and C (knowing that A is connected to B which is connected to C but C is not connected to A directly.

Here is what I implemented :

node(noA).
node(noB).
node(noC).

edge(noA,noB).
edge(noB,noC).

connected(X,Y):- edge(X,Y).
connected(X,Y):- edge(Y,X).

exists_way(X,Y):-
    connected(X,Z),
    connected(Y,Z).

But of course it does not apply to a bigger cluster with a lot of letters...

Could anyone of you help me ?

Thank you very much in advance !

Flóki
  • 9
  • 2
  • exists_way/2 should be recursive, to be able to join multiple connections together to form a path. – brebs Dec 17 '21 at 17:06
  • Does this answer your question? [Define graph in Prolog: edge and path, finding if there is a path between two vertices](https://stackoverflow.com/questions/21161624/define-graph-in-prolog-edge-and-path-finding-if-there-is-a-path-between-two-ve) – Armatorix Dec 18 '21 at 16:07

0 Answers0