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))).