This commit is contained in:
2023-12-08 23:10:03 -08:00
parent bdf5fe807a
commit 7624131aa2
6 changed files with 447 additions and 0 deletions

12
09/part2.pl Normal file
View File

@@ -0,0 +1,12 @@
start :-
input(Input),
findall(P, (member(L, Input), predict(L, P)), 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.