a-conjecture-of-mine

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

Commit
c39e241cf1022dbdf765dc7c22cbaa3e544de349
Parent
4a8f41f1ee7d2bc408a466941c5b3d889324f821
Author
Pablo Escobar Gaviria <gark.garcia@protonmail.com>
Date

Cleaned the Prolog implementation.

Diffstat

2 files changed, 13 insertions, 12 deletions

Status File Name N° Changes Insertions Deletions
Modified .gitignore 3 2 1
Modified script.pl 22 11 11
diff --git a/.gitignore b/.gitignore
@@ -3,9 +3,10 @@
 *.img
 *.IMG
 *.beam
-*.ja*.jarr
+*.jar
 bin
 build
 *.un~
+extra.pl
 Latex
 Cuda
diff --git a/script.pl b/script.pl
@@ -3,14 +3,14 @@
 % Let S: N -> N be the sum of the digits of a positive integer.
 % For all A and B in N, S(A + B) = S(A) + S(B) - 9k, where k is an integer.
 
-sum_digits(X, Y) :- sum_digits_acc(X, 0, Y).
+sum_digits(X, Y) :- sum_digits(X, 0, Y).
 
-sum_digits_acc(X, A, Y) :- X < 10, !, Y is A + X.
-sum_digits_acc(X, A, Y) :-
-    Q  = X div 10,
-    R  = X mod 10,
-    A2 = A + R,
-    sum_digits_acc(Q, A2, Y).
+sum_digits(X, Acc, Y) :- X < 10, !, Y is Acc + X.
+sum_digits(X, Acc, Y) :-
+    Q = X div 10,
+    R = X mod 10,
+    Acc1 = Acc + R,
+    sum_digits(Q, Acc1, Y).
 
 test_pair(A, B) :-
     R  = 0,
@@ -22,9 +22,9 @@ test_pair(A, B) :-
     D   = SC - SAB,
     R =:= D mod 9.
 
-iter(A, B) :-
-    forall(between(0, B, X), test_pair(A, X)).
+iter(A) :-
+    forall(between(0, A, B), test_pair(A, B)).
 
-conjecture(M) :-
-    forall(between(0, M, X), iter(X, X)).
+conjecture(Mod) :-
+    forall(between(0, Mod, A), iter(A)).