aoc23/08/part1.pl

17 lines
502 B
Perl
Raw Permalink Normal View History

2023-12-08 19:10:35 -06:00
:- op(700, xfx, l).
:- op(700, xfx, r).
From l To :- From to To-_.
From r To :- From to _-To.
answer(Answer) :- path([], aaa, Path), length(Path, Answer).
path(_, zzz, []) :- !. % getting full path instead of just length for debugging
path(Directions, From, [Move | Cdr]) :-
next_step(Directions, Move, Remain),
G =.. [Move, From, To], G,
path(Remain, To, Cdr).
next_step([Move | Remain], Move, Remain).
next_step([], Move, Remain) :- direction(Str), atom_chars(Str, [Move | Remain]).