(Scheme) ;; This is a program in PLT Scheme, a.k.a. mzscheme
(define (count-matches re str start-pos)
(let ((m (regexp-match-positions re str start-pos)))
(if m (+ 1 (count-matches re str (+ (caar m) 1))) 0)))
(define (matches-n-in-zero-to-k fn n)
(do ((sum-so-far 1)
(k (+ n 1))
(re (regexp (format "~a" n))))
((fn sum-so-far k) k)
(when (equal? 0 (modulo k 1000000))
(display (format "~a ~a ~a\n" n k sum-so-far)))
(set! k (+ k 1))
(set! sum-so-far
(+ sum-so-far (count-matches re (format "~a" k) 0)))))
(define (s n)
(matches-n-in-zero-to-k > n))
|