FallenBlade
Programmer
I have a file containing how stations in the London underground are linked.
For example:
I have written code to find a route from one station to another, here:
It works fine, apart from if it get's caught in a loop of stations before reaching the destination station.
Is there anyway I can stop the looping?
Thank you.
Tom
For example:
Code:
% CIRCLE LINE
connected(high_st_kensington,notting_hill_gate,circle).
connected(notting_hill_gate,bayswater,circle).
% NORTHERN LINE (left branch)
connected(mornington_crescent,euston,northern_l).
connected(euston,warren_st,northern_l).
I have written code to find a route from one station to another, here:
Code:
:-[tube].
route(X,Z) :-
connected(X,Z,_),
write('From '),write(X),nl,
write('Arrive at '),write(Z),nl,nl.
route(X,Z) :-
connected(X,Y),
write('From '),write(X),nl,
write('To '),write(Y),nl,nl,
route(Y,Z).
It works fine, apart from if it get's caught in a loop of stations before reaching the destination station.
Is there anyway I can stop the looping?
Thank you.
Tom