a-conjecture-of-mine

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

commit 6460f6000205d7e2be2d872b1a5b1bb2cb65f932
parent 4b1e1f1d839e88520beb84a69850002e96fa7402
Author: Pablo Emilio Escobar Gaviria <pablo-escobar@riseup.net>
Date:   Sat, 26 Sep 2020 23:52:43 -0300

Fixed small errors

Diffstat:
Mc/main.c | 7++-----
Mscript.js | 2+-
Mscript.rkt | 16+++++++---------
3 files changed, 10 insertions(+), 15 deletions(-)
diff --git a/c/main.c b/c/main.c
@@ -20,7 +20,7 @@
 // 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.
 
-int sum_digits(unsigned n)
+int sum_digits(unsigned int n)
 {
     int parc = n;
     int sum = 0;
@@ -47,14 +47,11 @@ int counterexempl(int max, int *sums_cache)
 
 int main(int argc, char *argv[])
 {
-    if (argc > 2)
+    if (argc > 1)
     {
         unsigned int max = strtoul(argv[1], NULL, 10);
 	      if (!max) return INVALID_INPUT;
 
-        unsigned int n_threads = strtoul(argv[2], NULL, 10);
-        if (!n_threads) return INVALID_INPUT;
-
         // Create the sums cache
         int *sums_cache = malloc(sizeof(int) * (2 * max + 1));
         for (int i = 0; i <= 2 * max + 1; i++)
diff --git a/script.js b/script.js
@@ -15,7 +15,7 @@ function sumDigits(n) {
 }
 
 function getSums(max) {
-    return Array.from({length: 2 * max + 1}, (_, i) => sumDigits(i));
+    return Array.from({length: 2 * max}, (_, i) => sumDigits(i));
 }
 
 export function counterexempl(max) {
diff --git a/script.rkt b/script.rkt
@@ -10,20 +10,18 @@
 ;; Returns `#t` if a counterexemple was found between `0` and `m`.
 ;; Otherwise returns `#f`.
 (define (counterexempl? m)
+    (define (test a b sums-cache)
+        (let ([sum (lambda (n) (vector-ref sums-cache n))])
+             (zero? (remainder (- (sum (+ a b)) (sum a) (sum b)) 9))))
+    (define (iter a sums-cache)
+        (stream-fold (lambda (acc b) (and acc (test a b sums-cache))) 
+                     #t 
+                     (in-range a)))
     (let ([sums-cache (get-sums m)])
          (not (stream-fold (lambda (acc a) (and acc (iter a sums-cache)))
                            #t
                            (in-range m)))))
 
-(define (iter a sums-cache)
-    (stream-fold (lambda (acc b) (and acc (test a b sums-cache))) 
-                 #t 
-                 (in-range a)))
-
-(define (test a b sums-cache)
-    (let ([sum (lambda (n) (vector-ref sums-cache n))])
-         (zero? (remainder (- (sum (+ a b)) (sum a) (sum b)) 9))))
-
 (define (sum-digits n) 
     (define (sum-digits-tail n acc)
         (if (zero? n)