simplify d9p2

This commit is contained in:
Dory 2023-12-08 23:28:47 -08:00
parent 7624131aa2
commit 65267a5850

View File

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