Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: problem_16_plus
Fetching contributors…

Cannot retrieve contributors at this time

executable file 35 lines (30 sloc) 1.416 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
#!/usr/bin/env python3

ones = {'1': 'one', '2': 'two', '3': 'three', '4': 'four', '5': 'five',
        '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine', '0': ''}

tens = {'2': 'twenty', '3': 'thirty', '4': 'forty', '5': 'fifty',
        '6': 'sixty', '7': 'seventy', '8': 'eighty', '9': 'ninety'}

teens = {'10': 'ten', '11': 'eleven', '12': 'twelve', '13': 'thriteen',
         '14': 'fourteen', '15': 'fifteen', '16': 'sixteen', '17': 'seventeen',
         '18': 'eighteen', '19': 'nineteen'}

hundreds = {0: 0, 1: "onehundredand", 2: "twohundredand",
            3: "threehundredand", 4: "fourhundredand",
            5: "fivehundredand", 6: "sixhundredand",
            7: "sevenhundredand", 8: "eighthundredand",
            9: "ninehundredand"
           }

if __name__ == "__main__":
    tot = 0
    for h in range(10):
        for y in range(1,100):
            try:
                t,o = tuple(str(y))
                if t is '1':
                    tot += len("{h}{t}".format(h=hundreds[h], t=teens[t + o]))
                else:
                    tot += len("{h}{t}{o}".format(h = hundreds[h], t=tens[t],
                                                  o=ones[o]))
            except ValueError:
                    tot += len("{h}{o}".format(h= hundreds[h], o=ones[str(y)]))
                    print("{h}{o}".format(h= hundreds[h], o=ones[str(y)]))
    tot += len('onethousand')
    print(tot)
Something went wrong with that request. Please try again.