Comment detail

アルファベットの繰り上がり (Nested Flatten)

This comment is reply for 1049 匿名: 変形26進法ですね (アルファベットの繰り上がり). Go to thread root.

同じく#1049のPythonのコードをSchemeで。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
(define (convert n)
  (let* ((nums "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
	 (digit (string (string-ref nums (remainder (- n 1) (string-length nums)))))
	 (n (quotient (- n 1) (string-length nums))))
    (if (not (zero? n))
	(string-append (convert n) digit)
        digit)))

(let loop ((n 1) (m 1000))
  (cond ((<= n m)
         (display (convert n))
         (and (not (= n m)) (display ", "))
         (loop (+ n 1) m))
        (else (display #\newline))))

Index

Feed

Other

Link

Pathtraq

loading...