d8
This commit is contained in:
16
08/part1.pl
Normal file
16
08/part1.pl
Normal file
@@ -0,0 +1,16 @@
|
||||
:- 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]).
|
Reference in New Issue
Block a user