- Commit
- 148a072a45dbfb57d58f98e8d9a2c38089cb51e4
- Parent
- ab68089e4f0a13dda9eeb8d37f9b70f2bee405b2
- Author
- Pablo Escobar Gaviria <gark.garcia@protonmail.com>
- Date
Cleaned the Racket implementation.
An exercise on polyglossy: the same problem solved on multiple languages
Cleaned the Racket implementation.
1 file changed, 9 insertions, 9 deletions
Status | File Name | N° Changes | Insertions | Deletions |
Modified | script.rkt | 18 | 9 | 9 |
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))