im trying to write a program in prolog that determine if there is a way from place to place. these are the relations:
road(ny,florida).
road(washington,florida).
road(washington,texas).
road(vegas,california).
I want to write: there_is_way(X,Y)
that determine if there is a way or not.
for example:
?- road(florida,ny).
no
?-there_is_way(florida,ny).
yes
This is my code:
there_is_way(X,Y):- road(X,Y);
road(Y,X);
road(X,Z),road(Z,Y),X\=Y;
road(X,Z),road(Y,Z),X\=Y;
road(Z,X),road(Z,Y),X\=Y;
road(Z,X),road(Y,Z),X\=Y.
there_is_way(X,Y):-
road(Z,Y),there_is_way(X,Z).
there_is_way(X,Y):-
road(Y,Z),there_is_way(X,Z).
but unfortunately I get "Error 1, Backtrack Stack Full".
someone?
thank you