コード。

(define (next digits)
  (let ((tab (map (lambda (n) (cons n 0)) '(0 1 2 3 4 5 6 7 8 9))))
    (for-each (lambda (num)
                (let ((p (list-ref tab num)))
                  (set-cdr! p (+ (cdr p) 1))))
              digits)
    (apply append
           (map (lambda (p) (if (= (cdr p) 0) '() (list (cdr p) (car p))))
                (reverse tab)))))

(define (rumakan-series init repeat)
  (let loop ((repeat repeat)
             (n      init)
             (n+1    (next init)))
    (cond ((zero? repeat) (display "Give up") (newline))
          ((equal? n n+1) (display "Convergenced") (newline))
          (else (write n+1) (newline) (loop (- repeat 1) n+1 (next n+1))))))

実行例。

STk> (rumakan-series '(0) 20)
(1 0)
(1 1 1 0)
(3 1 1 0)
(1 3 2 1 1 0)
(1 3 1 2 3 1 1 0)
(2 3 1 2 4 1 1 0)
(1 4 1 3 2 2 3 1 1 0)
(1 4 2 3 2 2 4 1 1 0)
(2 4 1 3 3 2 3 1 1 0)
(1 4 3 3 2 2 3 1 1 0)
Convergenced
STk> (rumakan-series '(9 9 9 9) 20)
(4 9)
(1 9 1 4)
(1 9 1 4 2 1)
(1 9 1 4 1 2 3 1)
(1 9 1 4 1 3 1 2 4 1)
(1 9 2 4 1 3 1 2 5 1)
(1 9 1 5 1 4 1 3 2 2 4 1)
(1 9 1 5 2 4 1 3 2 2 5 1)
(1 9 2 5 1 4 1 3 3 2 4 1)
(1 9 1 5 2 4 2 3 2 2 4 1)
(1 9 1 5 2 4 1 3 4 2 3 1)
(1 9 1 5 2 4 2 3 2 2 4 1)
(1 9 1 5 2 4 1 3 4 2 3 1)
(1 9 1 5 2 4 2 3 2 2 4 1)
(1 9 1 5 2 4 1 3 4 2 3 1)
(1 9 1 5 2 4 2 3 2 2 4 1)
(1 9 1 5 2 4 1 3 4 2 3 1)
(1 9 1 5 2 4 2 3 2 2 4 1)
(1 9 1 5 2 4 1 3 4 2 3 1)
(1 9 1 5 2 4 2 3 2 2 4 1)
Give up

Shiro Kawai
Last modified: Thu Mar 23 09:44:22 HST 2000