Created
June 4, 2012 13:12
-
-
Save kaakaa/2868280 to your computer and use it in GitHub Desktop.
みなとRuby会議01 ソーシャルコーディング EnglishNumerals
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
# -*- encoding: UTF-8 -*- | |
input = ARGV[0].to_i | |
array = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] | |
array2 = ['','hoge', 'twenty', 'thirty', 'fourty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'] | |
array2_1 = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'] | |
def hundred(number) | |
return number + ' hundred' | |
end | |
def under_hundred(ten) | |
str = '' | |
if ten/10 == 1 then | |
str = array2_1[ten%10] | |
else | |
str = array2[ten/10] + array[ten%10] | |
end | |
return str | |
end | |
if input.to_s.length == 1 then | |
p array[input] | |
elsif input.to_s.length == 2 then | |
if input/10 == 1 then | |
p array2_1[input%10] | |
else | |
p array2[input/10] | |
p array[input%10] | |
end | |
elsif input.to_s.length == 3 then | |
#p array[input/100] + ' hundred' | |
p hundred(array[input/100]) | |
p array2[input%100/10] | |
p array[input%100%10] | |
elsif input.to_s.length == 4 then | |
sen = input / 100 | |
if sen < 20 | |
p array2_1[sen%10] + ' hundred' | |
else | |
p array2[sen/10] | |
p array[sen%10] + ' hundred' | |
end | |
ten = input % 100 | |
if ten/10 == 1 then | |
p array2_1[ten%10] | |
else | |
p array2[ten/10] | |
p array[ten%10] | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment