```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 ``` ```; counting zeros (define (filter pred? xs) (let loop ((xs xs) (ys '())) (cond ((null? xs) (reverse ys)) ((pred? (car xs)) (loop (cdr xs) (cons (car xs) ys))) (else (loop (cdr xs) ys))))) (define (digits n . args) (let ((b (if (null? args) 10 (car args)))) (let loop ((n n) (d '())) (if (zero? n) d (loop (quotient n b) (cons (modulo n b) d)))))) (define (count-zeros num) (let loop ((num num) (count 0)) (if (zero? num) count (let ((zeros (length (filter zero? (digits num))))) (loop (- num 1) (+ count zeros)))))) (display (count-zeros 100)) (newline) (define (count-zeros num) (let loop ((f 0) (z 0) (n 0) (ns (digits num))) (if (null? ns) f (loop (+ (* 10 f) n (- (* z (- 9 (car ns))))) (if (zero? (car ns)) (+ z 1) z) (+ (* 10 n) (car ns)) (cdr ns))))) (display (count-zeros 1000000000000)) (newline) (define (count-zeros num m) (let loop ((f 0) (z 0) (n 0) (ns (digits num))) (if (null? ns) f (loop (modulo (+ (* 10 f) n (- (* z (- 9 (car ns))))) m) (if (zero? (car ns)) (+ z 1) z) (+ (* 10 n) (car ns)) (cdr ns))))) (display (count-zeros (expt 10 10000) 12345678923)) (newline) ```
 ```1 2 3 ``` ```11 1088888888901 2646381410 ```