Skip to content

Instantly share code, notes, and snippets.

@asflash8
Created June 2, 2012 08:59
Show Gist options
  • Save asflash8/2857437 to your computer and use it in GitHub Desktop.
Save asflash8/2857437 to your computer and use it in GitHub Desktop.
みなとRuby会議01 ソーシャルコーディング EnglishNumerals
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(' ')
@asflash8
Copy link
Author

asflash8 commented Jun 2, 2012

みなとRuby会議でやったソーシャルコーディングの課題をやってみた

仕様
・引数で与えられた整数を英語で表示させること
・0~9999まで対応すること
・ハイフンや"and"などの揺れは得に指定なし

泥臭いしRubyっぽくないけどせっかく書いたので初Gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment