a-conjecture-of-mine

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

commit 148a072a45dbfb57d58f98e8d9a2c38089cb51e4
parent ab68089e4f0a13dda9eeb8d37f9b70f2bee405b2
Author: Pablo Escobar Gaviria <gark.garcia@protonmail.com>
Date:   Tue, 21 Jan 2020 14:59:31 -0200

Cleaned the Racket implementation.

Diffstat:
Mscript.rkt | 18+++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/script.rkt b/script.rkt
@@ -1,11 +1,15 @@
 #lang racket
 
+; This script is a simple test for the following conjecture:
+
+; 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 interger.
+
 (provide counterexempl)
 
 (define (counterexempl max)
     (let ([sums-cache (get-sums max)])
-         (not
-              (foldl (lambda (acc a) (and acc (iter a sums-cache)))
+         (not (foldl (lambda (acc a) (and acc (iter a sums-cache)))
                      #t
                      (in-range max)))))
 
@@ -13,11 +17,8 @@
     (foldl (lambda (acc b) (and acc (test a b sums-cache))) #t (in-range a)))
 
 (define (test a b sums-cache)
-    (let ([sum-digits (lambda (n) (vector-ref sums-cache n))])
-         (zero?
-             (remainder 
-                 (- (sum-digits (+ a b)) (sum-digits a) (sum-digits b)) 
-                 9))))
+    (let ([sum (lambda (n) (vector-ref sums-cache n))])
+         (zero? (remainder (- (sum (+ a b)) (sum a) (sum b)) 9))))
 
 (define (sum-digits n) (sum-digits-tail n 0))
 
@@ -26,6 +27,5 @@
         acc
         (sum-digits-tail (floor n 10) (+ acc (remainder n 10)))))
 
-(define (get-sums max)
-    (build-vector (+ (* 2 max) 1) sum-digits))
+(define (get-sums max) (build-vector (+ (* 2 max) 1) sum-digits))