diff --git a/script.pl b/script.pl
@@ -3,34 +3,27 @@
% 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_acc(X, X, A) :- X < 10, A is 0, !.
-sum_digits_acc(X, Y, A) :-
- X >= 10,
- X1 is div(X, 10),
- X2 is mod(X, 10),
- sum_digits_acc(X1, A, _),
- Y is A + X2.
+sum_digits(X, Y) :- sum_digits_acc(X, 0, Y).
-sum_digits(X, Y) :- sum_digits_acc(X, 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).
test_pair(A, B) :-
- R is 0,
- AB is A + B,
+ R = 0,
+ AB = A + B,
sum_digits(A, SA),
sum_digits(B, SB),
sum_digits(AB, SC),
- SAB is SA + SB,
- D is SC - SAB,
- R is mod(D, 9).
+ SAB = SA + SB,
+ D = SC - SAB,
+ R =:= D mod 9.
-iter(A, 0) :- test_pair(A, 0), !.
iter(A, B) :-
- test_pair(A, B),
- C is B - 1,
- iter(A, C).
+ forall(between(0, B, X), test_pair(A, X)).
-conjecture(0) :- test_pair(0, 0), !.
conjecture(M) :-
- iter(M, M),
- N is M - 1,
- conjecture(N).-
\ No newline at end of file
+ forall(between(0, M, X), iter(X, X)).+
\ No newline at end of file