Skip to content

Instantly share code, notes, and snippets.

@Mouq
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mouq/9029616 to your computer and use it in GitHub Desktop.
Save Mouq/9029616 to your computer and use it in GitHub Desktop.
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 文字输入 ~ " 等于 " ~ 成为普通话 结果;
}
}
$ perl6 chinese-math.p6
公式 > (三)百 加 (三)百
(三)百 加 (三)百 等于 六百零十零
公式 > (六)百 加 (零)十 加 零
(六)百 加 (零)十 加 零 等于 六百零十零
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment