(define (kansuji-tani exp)
(case exp
[(0) ""]
[(1) "十"]
[(2) "百"]
[(3) "千"]))
(define *man-ijyou* '("" "万" "億" "兆" "京" "垓" "予" "穣" "溝" "澗" "正" "載" "極" "恒河沙" "阿僧祇" "那由多" "不可思議" "無量大数"))
(define(kansuji num)
(case num
((9) "九")
((8) "八")
((7) "七")
((6) "六")
((5) "五")
((4) "四")
((3) "三")
((2) "二")
((1) "一")
((0) "")))
(define (number->kansuji num)
(string-join (reverse (map (lambda (el1 el2) (if (not (string=? el1 ""))
(string-join (list el1 el2) "")
""))
(reverse (map ichi-sen (map (lambda (n) (map kansuji n)) (map number->list (bunkai num)))))
*man-ijyou*)) ""))
(define (bunkai num)
(let loop ((q (quotient num 10000))
(m (modulo num 10000))
(result '()))
(if (zero? q)
(cons m result)
(loop (quotient q 10000) (modulo q 10000) (cons m result)))))
(define (number->list n :optional (k (if (= n 1000) 3 (truncate (log n 10)))))
; (log 1000 10)が2.9999999999999996で切り捨てだと3に成らないため
(let loop ((keta k) (result '()) (m n))
(if (< keta 0)
(reverse result)
(let ((tani (expt 10 keta)))
(loop (- keta 1)
(cons (inexact->exact (quotient m tani)) result)
(- m (* (quotient m tani) tani)))))))
(define (ichi-sen lis)
(let loop ((ls lis)
(keta (- (length lis) 1))
(result '()))
(if (>= keta 0)
(let1 ns (car ls)
(cond [(and (not (string=? ns "")) (string=? ns "一") (> keta 0))
(set! result (cons (kansuji-tani keta) result))]
[(not (string=? ns ""))
(set! result (cons (kansuji-tani keta) (cons ns result)))]
[(string=? ns "")
(set! result (cons ns result))])
(loop (cdr ls) (- (length (cdr ls)) 1) result))
(string-join (reverse result) ""))))
(number->kansuji (+ (* 2 (expt 10 68)) (* 3 (expt 10 64)) (expt 10 60) 47810478801748017480174803748971890478921047801749032174))
; "二無量大数三不可思議一那由多四千七百八十一恒河沙四百七十八極八千十七載四千八百一正七千四百八十澗千七百四十八溝三百七十四穣八千九百七十一予八千九百四垓七千八百九十二京千四十七兆八千十七億四千九百三万二千百七十四"