Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f4c4eaeba4
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 49 lines (44 sloc) 1.136 kb
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48
# How many letters would be needed to write all the numbers in words from 1 to 1000?

textual = {}
textual[1] = "one"
textual[2] = "two"
textual[3] = "three"
textual[4] = "four"
textual[5] = "five"
textual[6] = "six"
textual[7] = "seven"
textual[8] = "eight"
textual[9] = "nine"
textual[10] = "ten"
textual[11] = "eleven"
textual[12] = "twelve"
textual[13] = "thirteen"
textual[14] = "fourteen"
textual[15] = "fifteen"
textual[16] = "sixteen"
textual[17] = "seventeen"
textual[18] = "eighteen"
textual[19] = "nineteen"
textual[20] = "twenty"
textual[30] = "thirty"
textual[40] = "forty"
textual[50] = "fifty"
textual[60] = "sixty"
textual[70] = "seventy"
textual[80] = "eighty"
textual[90] = "ninety"

def get_textual(i):
  if textual.has_key(i):
    return textual[i]

  if 10 < i < 100:
    num = int(str(i)[0] + "0")
    return get_textual(num) + get_textual(i - num)
  elif 100 <= i < 1000:
    num = int(str(i)[0] + "00")
    n = get_textual(i / 100) + "hundred"
    if i - num > 0:
      n += "and" + get_textual(i - num)
    return n
  else:
    return "onethousand"

print len("".join([get_textual(i) for i in range(1, 1001)]))
Something went wrong with that request. Please try again.