I have a problem of linking small-town NZ via a Prolog program. I have been given a set of data which is the roads, their to and from's and the distance. I thought the first problem would be straight-forward but I have been pulling my hair our for hours on this with no luck, all I have to do is print out a viable path given a route. Why can't the solution below find a correct path?
road('Wellington', 'Palmerston North', '143').
road('Palmerston North', 'Wanganui', '74').
road('Palmerston North', 'Napier', '178').
road('Palmerston North', 'Taupo', '259').
road('Wanganui', 'Taupo', '231').
road('Wanganui', 'New Plymouth', '163').
road('Wanganui', 'Napier', '252').
road('Napier', 'Taupo', '147').
road('Napier', 'Gisborne', '215').
road('New Plymouth', 'Hamilton', '242').
road('New Plymouth', 'Taupo', '289').
road('Taupo', 'Hamilton', '153').
road('Taupo', 'Rotorua', '82').
road('Taupo', 'Gisborne', '334').
road('Gisborne', 'Rotorua', '291').
road('Rotorua', 'Hamilton', '109').
road('Hamilton', 'Auckland', '126').
route(Current, Finish, []) :- route(Current, Finish, [Current]).
route(Current, Finish, _) :- Current==Finish.
route(Current, Finish, Visits) :- traverse(Current, Next, Visits), route(Next, Finish, Visits).
traverse(Current, Next, [Next|_]) :- road(Current, Next, _).
Whenever I call: route('Wellington','Napier', X). It fails despite there being a path, Wellington->Palmerston North->Napier. Thanks in advance, I know I'm probably doing something stupid as I am new to Prolog.