correct d8p2 and add debug print

This commit is contained in:
Dory 2023-12-09 08:48:27 -08:00
parent 65267a5850
commit 1a7326555a

View File

@ -8,10 +8,11 @@ From r To :- From to _-To.
answer(Answer) :-
starts(Starts),
routes(Starts, Routes),
collapse_routes(Routes, _-(Answer-_-_)).
collapse_routes(Routes, _-(_-Answer-_)).
collapse_routes([X], X).
collapse_routes(Routes, Collapsed) :-
writef('Collapsing: %t\n', [Routes]),
sort(2, @=<, Routes, [Route1, Route2 | CdrRoutes]),
unify2(Route1, Route2, 0-0-0-0, [], NewRoute),
collapse_routes([NewRoute | CdrRoutes], Collapsed).