abstract foldl to product call with custom times accumulator

This commit is contained in:
wi11-holdsworth 2025-08-26 21:33:46 +10:00
parent 9fbc6297f9
commit a568d59ce6

16
main.pl
View file

@ -28,12 +28,20 @@ valid_row([Head|Tail]) :-
%
valid_head(Head, List) :-
sum(List, #=, Head)
; foldl(mul, List, 1, Head).
; product(List, Head).
%% mul
%% product(+List, -Product)
%
mul(X, Acc, New) :-
New #= Acc * X.
product(List, Product) :-
foldl(times, List, 1, Product).
%% times(?Int1, ?Int2, ?Int3)
%
% true if Int3 #= Int1 * Int2
times(Int1, Int2, Int3) :-
Int3 #= Int1 * Int2.
%% unify_diagonal(+Puzzle)