I have this program:
region(r1, 2110, [1,2]).
region(r2, 2210, [4,5,8]).
region(r3, 2310, [3,6]).
region(r4, 2410, [7,10,11,15]).
region(r5, 2510, [9,12]).
region(r6, 2610, [13,14]).
telephone(2310-6-64221, name(asd, nikos)).
telephone(2510-12-24234, name(dsa, kiki)).
next_to(2, 1).
next_to(1,4).
next_to(4, 5).
next_to(4, 8).
next_to(3, 6).
next_to(3, 5).
next_to(5, 8).
next_to(8, 9).
next_to(6, 7).
next_to(7, 10).
next_to(9, 12).
next_to(10, 11).
next_to(10, 15).
next_to(12, 15).
next_to(13, 14).
connect(X, Y) :-
next_to(X, Y).
connect(X, Y) :-
next_to(Y, X).
pathloop(Start, End, _, Path) :-
connect(Start, End),
Path = [Start, End].
pathloop(Start, End, Visited, Path) :-
connect(Start, Middle),
not(member(Middle, Visited)),
pathloop(Middle, End, [Middle|Visited], PathRest),
Path = [Start|PathRest].
can_call(PersonA, PersonB, Route) :-
telephone(_-Area1-_, name(PersonA, _)),
telephone(_-Area2-_, name(PersonB, _)),
pathloop(Area1, Area2,_, Route).
Everything runs except pathloop
the base runs but the recursive one must to display a list Path
which contains a path from A to B. But when i run the program and i type ?- can_call(asd, dsa, Route)
,
it fails (returns false
.). What I have to change on pathloop
? i tried
?- pathloop(1, 5, [], Path).
and it shows 10-20 results and then false
.