a-conjecture-of-mine

An exercise on polyglossy: the same problem solved on multiple languages

commit a1cd8c3a5d8223b16919f0ba1d53096d137e6723
parent e0933798b0fdbae94bf4fe49334e47920dbf74fd
Author: Pablo Emilio Escobar Gaviria <pablo-escobar@riseup.net>
Date:   Fri, 25 Sep 2020 20:11:17 -0300

Made the Prolog implementation more eloquent

Diffstat:
Mscript.pl | 24+++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/script.pl b/script.pl
@@ -7,24 +7,18 @@ sum_digits(X, Y) :- sum_digits_acc(X, 0, Y).
 
 sum_digits_acc(0, Acc, Acc) :- !.
 sum_digits_acc(X, Acc, Y) :-
-    Q = X div 10,
-    R = X mod 10,
-    Acc1 = Acc + R,             % Accumulate value
+    Q is X div 10,
+    R is X mod 10,
+    Acc1 is Acc + R,            % Accumulate value
     sum_digits_acc(Q, Acc1, Y). % Propagate Y (result) from recursion back up
 
 test_pair(A, B) :-
-    R  = 0,
-    AB = A + B,
-    sum_digits(A, SA),
-    sum_digits(B, SB),
-    sum_digits(AB, SC),
-    SAB = SA + SB,
-    D   = SC - SAB,
-    R =:= D mod 9.
-
-iter(A) :-
-    forall(between(0, A, B), test_pair(A, B)).
+    sum_digits(A, X),
+    sum_digits(B, Y),
+    sum_digits(A + B, Z),
+    D   = Z - X - Y,
+    0 =:= D mod 9.
 
 conjecture(Max) :-
-    forall(between(0, Max, A), iter(A)).
+    forall(between(0, Max, A), forall(between(0, A, B), test_pair(A, B))).