Michael F. wrote:
…or even better…
http://p.ramaze.net/1900
my stab at it
^ manveru
I did something slightly different, which works on multiple levels, not
just two. For example, it can go all the way up to 999 without any
extra code.
#!/usr/bin/env ruby
class Fixnum
ENGLISH = {
0 => ‘zero’,
1 => ‘one’,
2 => ‘two’,
3 => ‘three’,
4 => ‘four’,
5 => ‘five’,
6 => ‘six’,
7 => ‘seven’,
8 => ‘eight’,
9 => ‘nine’,
10 => 'ten',
11 => 'eleven',
12 => 'twelve',
13 => 'thirteen',
14 => 'fourteen',
15 => 'fifteen',
16 => 'sixteen',
17 => 'seventeen',
18 => 'eighteen',
19 => 'ninteen',
20 => 'twenty',
30 => 'thirty',
40 => 'forty',
50 => 'fifty',
60 => 'sixty',
70 => 'seventy',
80 => 'eighty',
90 => 'ninety',
100 => 'one hundred and',
200 => 'two hundred and',
300 => 'three hundred and',
400 => 'four hundred and',
500 => 'five hundred and',
600 => 'six hundred and',
700 => 'seven hundred and',
800 => 'eight hundred and',
900 => 'nine hundred and'
}
def to_english
i = ENGLISH.keys.select{|n| n <= self}.max
ENGLISH[i] + (i < self ? " " + (self-i).to_english : ‘’)
end
end
99.downto(1) do|i|
puts “#{i.to_english} bottles of beer on the wall”
end