- Commit
- 7fc0c8aee453c1ac1f07b0170a42a43d2b559dab
- Parent
- 148a072a45dbfb57d58f98e8d9a2c38089cb51e4
- Author
- Pablo Escobar Gaviria <gark.garcia@protonmail.com>
- Date
Fixed minor syntax errors in `script.rkt`.
An exercise on polyglossy: the same problem solved on multiple languages
Fixed minor syntax errors in `script.rkt`.
2 files changed, 6 insertions, 4 deletions
Status | File Name | N° Changes | Insertions | Deletions |
Modified | script.pl | 2 | 1 | 1 |
Modified | script.rkt | 8 | 5 | 3 |
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))