(Scheme) ;; This is a program in PLT Scheme, a.k.a. mzscheme
(define (countmatches re str startpos)
(let ((m (regexpmatchpositions re str startpos)))
(if m (+ 1 (countmatches re str (+ (caar m) 1))) 0)))
(define (matchesninzerotok fn n)
(do ((sumsofar 1)
(k (+ n 1))
(re (regexp (format "~a" n))))
((fn sumsofar k) k)
(when (equal? 0 (modulo k 1000000))
(display (format "~a ~a ~a\n" n k sumsofar)))
(set! k (+ k 1))
(set! sumsofar
(+ sumsofar (countmatches re (format "~a" k) 0)))))
(define (s n)
(matchesninzerotok > n))
