a-conjecture-of-mine

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

commit 7fc0c8aee453c1ac1f07b0170a42a43d2b559dab
parent 148a072a45dbfb57d58f98e8d9a2c38089cb51e4
Author: Pablo Escobar Gaviria <gark.garcia@protonmail.com>
Date:   Wed, 22 Jan 2020 12:02:37 -0200

Fixed minor syntax errors in `script.rkt`.

Diffstat:
Mscript.pl | 2+-
Mscript.rkt | 8+++++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/script.pl b/script.pl
@@ -5,7 +5,7 @@
 
 sum_digits(X, Y) :- sum_digits_tail(X, 0, Y).
 
-sum_digits_tail(X, Acc, Y) :- X < 10, !, Y is Acc + X.
+sum_digits_tail(0, Acc, Y) :- Y =:= Acc.
 sum_digits_tail(X, Acc, Y) :-
     Q = X div 10,
     R = X mod 10,
diff --git a/script.rkt b/script.rkt
@@ -9,12 +9,14 @@
 
 (define (counterexempl max)
     (let ([sums-cache (get-sums max)])
-         (not (foldl (lambda (acc a) (and acc (iter a sums-cache)))
+         (not (stream-fold (lambda (acc a) (and acc (iter a sums-cache)))
                      #t
                      (in-range max)))))
 
 (define (iter a sums-cache)
-    (foldl (lambda (acc b) (and acc (test a b sums-cache))) #t (in-range a)))
+    (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))])
@@ -25,7 +27,7 @@
 (define (sum-digits-tail n acc)
     (if (zero? n)
         acc
-        (sum-digits-tail (floor n 10) (+ acc (remainder n 10)))))
+        (sum-digits-tail (quotient n 10) (+ acc (remainder n 10)))))
 
 (define (get-sums max) (build-vector (+ (* 2 max) 1) sum-digits))