aoc23/09/part2.pl

12 lines
317 B
Perl
Raw Normal View History

2023-12-09 01:10:03 -06:00
start :-
input(Input),
2023-12-09 01:28:47 -06:00
maplist(predict, Input, Ps),
2023-12-09 01:10:03 -06:00
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),
2023-12-09 01:28:47 -06:00
L = [L1 | _], X is L1 - SubX.