Last active
August 29, 2015 14:11
-
-
Save ramoncaldeira/af2ce5344a5a22382aca 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
UNITS = Hash[(1..9).zip %w(um dois tres quatro cinco seis sete oito nove)] | |
SPECIAL = Hash[(11..19).zip %w(onze doze treze quatorze quinze dezesseis dezessete dezoito dezenove)] | |
DOZENS = Hash[(1..9).zip %w(dez vinte trinta quarenta cinquenta sessenta setenta oitenta noventa)] | |
def to_words(number) | |
return SPECIAL[number] if number.between?(11, 19) | |
dozens, units = number.divmod(10) | |
[DOZENS[dozens], UNITS[units]].compact.join(' e ') | |
end | |
# main program | |
(1..99).each do |n| | |
puts to_words(n) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment