Created
June 2, 2012 08:59
-
-
Save asflash8/2857437 to your computer and use it in GitHub Desktop.
みなとRuby会議01 ソーシャルコーディング EnglishNumerals
This file contains hidden or 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
num = ("%04d" % ARGV[0]).split(//).map(&:to_i) | |
num_singles = %W(zero one two three four five six seven eight nine) | |
num_teens = %W(ten eleven twelve thirteen fouteen fifteen sixteen seventeen eiteen nineteen) | |
num_tys = %W('' '' twenty thirty fourty fifty sixty seventy eighty ninety) | |
result = [] | |
result << num_singles[num[0]] + ' thousand and' if num[0] > 0 | |
result << num_singles[num[1]] + ' hundred and' if num[1] > 0 | |
result << num_tys[num[2]] if num[2] > 1 | |
result << num_teens[num[3]] if num[2] == 1 | |
result << num_singles[num[3]] if num[2] != 1 && num[3] != 0 | |
puts result.join(' ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
みなとRuby会議でやったソーシャルコーディングの課題をやってみた
仕様
・引数で与えられた整数を英語で表示させること
・0~9999まで対応すること
・ハイフンや"and"などの揺れは得に指定なし
泥臭いしRubyっぽくないけどせっかく書いたので初Gist