Comment detail

整数の漢数字表記 (Nested Flatten)
Squeak Smalltalk で。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
| 数 漢数字 |
数 := 1732050807568877.
漢数字 := ''.
#('' 万 億 兆 京) do: [:大位 |
    | 大位の数 |
    大位の数 := ''.
    #('' 十 百 千) do: [:小位 |
        | 小位の数 |
        小位の数 := #('' 一 二 三 四 五 六 七 八 九) at: 数 \\ 10 + 1.
        数 := 数 // 10.
        小位の数 ifNotEmpty: [
            (小位 notEmpty and: [小位の数 = '一']) ifTrue: [小位の数 := ''].
            大位の数 := 小位の数, 小位, 大位の数]].
    大位の数 ifNotEmpty: [漢数字 := 大位の数, 大位, 漢数字]].
^漢数字   "=> '千七百三十二兆五百八億七百五十六万八千八百七十七' "

Index

Feed

Other

Link

Pathtraq

loading...