simplify d9p2
This commit is contained in:
parent
7624131aa2
commit
65267a5850
@ -1,12 +1,11 @@
|
|||||||
start :-
|
start :-
|
||||||
input(Input),
|
input(Input),
|
||||||
findall(P, (member(L, Input), predict(L, P)), Ps),
|
maplist(predict, Input, Ps),
|
||||||
sum_list(Ps, Answer),
|
sum_list(Ps, Answer),
|
||||||
writef('Answer=%t\n', [Answer]).
|
writef('Answer=%t\n', [Answer]).
|
||||||
|
|
||||||
predict(L, 0) :- maplist(=:=(0), L), !.
|
predict(L, 0) :- maplist(=:=(0), L), !.
|
||||||
predict(L, X) :-
|
predict(L, X) :-
|
||||||
L = [L1 | CdrL],
|
|
||||||
foldl([Li1, Li2, C, D]>>(Li2 is Li1 - C, D = Li1), L, [_ | NewL], 0, _),
|
foldl([Li1, Li2, C, D]>>(Li2 is Li1 - C, D = Li1), L, [_ | NewL], 0, _),
|
||||||
predict(NewL, SubX),
|
predict(NewL, SubX),
|
||||||
X is L1 - SubX.
|
L = [L1 | _], X is L1 - SubX.
|
||||||
|
Loading…
Reference in New Issue
Block a user