aoc23/09/part2.pl
2023-12-08 23:28:47 -08:00

12 lines
317 B
Prolog

start :-
input(Input),
maplist(predict, Input, Ps),
sum_list(Ps, Answer),
writef('Answer=%t\n', [Answer]).
predict(L, 0) :- maplist(=:=(0), L), !.
predict(L, X) :-
foldl([Li1, Li2, C, D]>>(Li2 is Li1 - C, D = Li1), L, [_ | NewL], 0, _),
predict(NewL, SubX),
L = [L1 | _], X is L1 - SubX.