From a568d59ce63f1f24867b5be3c78d2951916d5c5f Mon Sep 17 00:00:00 2001 From: wi11-holdsworth <83637728+wi11-holdsworth@users.noreply.github.com> Date: Tue, 26 Aug 2025 21:33:46 +1000 Subject: [PATCH] abstract foldl to product call with custom times accumulator --- main.pl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.pl b/main.pl index dd6a468..6342348 100644 --- a/main.pl +++ b/main.pl @@ -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)