Last active
August 29, 2015 13:56
-
-
Save Mouq/9029616 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
# Partial solution to https://codegolf.stackexchange.com/questions/20957 | |
enum 数 <零 一 二 三 四 五 六 七 八 九 十>; | |
sub infix:<加> (\第一, \第二) { 第一 + 第二 } | |
sub infix:<减> (\第一, \第二) { 第一 - 第二 } | |
sub infix:<乘以> (\第一, \第二) { 第一 * 第二 } | |
sub infix:<除以> (\第一, \第二) { 第一 / 第二 } | |
sub infix:<等于> (\第一, \第二) { 第一 == 第二 } | |
sub postfix:<十> (\数) { 数 乘以 (五 加 五) } | |
sub postfix:<百> (\数) { 数 乘以 十 乘以 十 } | |
sub 成为普通话 (\量) { | |
数(量 div (一)百) ~ '百' ~ 数(量 div 十 % 十) ~ '十' ~ 数(量 % 十) | |
} | |
sub MAIN { | |
loop { | |
my \文字输入 = prompt('公式 > ') or next; | |
my \结果 = EVAL 文字输入; | |
say 文字输入 ~ " 等于 " ~ 成为普通话 结果; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ perl6 chinese-math.p6 | |
公式 > (三)百 加 (三)百 | |
(三)百 加 (三)百 等于 六百零十零 | |
公式 > (六)百 加 (零)十 加 零 | |
(六)百 加 (零)十 加 零 等于 六百零十零 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment