-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopg17.rb
34 lines (33 loc) · 841 Bytes
/
opg17.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$ones = ["", "one","two","three","four","five","six","seven","eight","nine"]
$teens = ["ten", "eleven","twelve","thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" ]
$tens = ["", "ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"]
def spellNumber(x)
result = ""
if x % 100 < 20 && x % 100 > 9 then
result = $teens[x % 10]
x = x / 100
else
result = $ones[x % 10]
x = x / 10
result = $tens[x % 10] + result
x = x / 10
end
if x == 0 then
return result
end
if result == "" then
result = $ones[x % 10] + "hundred"
else
result = $ones[x % 10] + "hundredand" + result
end
if x == 10 then
return "onethousand"
else
return result
end
end
total = ""
for i in 1...1001
total = total + spellNumber(i)
end
puts total.length