Comment detail

整数の漢数字表記 (Nested Flatten)
 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
(use text.tree)
(use util.list)

(define (positive->kansuji n)
  (define (keta-split n keta)
    (receive (q r) (quotient&remainder n keta)
             (if (< q keta)
                 (if (zero? q)
                     (list r)
                     (list r q))
                 (cons r (keta-split q keta)))))
  (define (add-tanni lst tanni)
    (fold
     (lambda (x t l)
       (cons (list (cond ((and (equal? 1 x) (not (equal? t ""))) "")
                         ((integer? x)
                          (list-ref '("" "一" "二" "三" "四" "五" "六" "七" "八" "九") x))
                         (else x))
                   (if (and (equal? 0 x) (not (equal? t "")))
                       ""
                       t))
             l))
     '() lst tanni))
  (tree->string
   (intersperse " " (add-tanni (map (lambda (n)
                                      (add-tanni (keta-split n 10)
                                                 '("" "十" "百" "千")))
                                    (keta-split n 10000))
                               '("" "万" "億" "兆")))))

Index

Feed

Other

Link

Pathtraq

loading...