Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 34 lines (28 sloc) 1.123 kb
8b65f9e 5 more problems to 50
skate authored
1 Len = {1:'one', 2:'two', 3:'three', 4:'four', 5:'five', 6:'six',
2 7:'seven', 8:'eight', 9:'nine', 10:'ten', 11:'eleven', 12:'twelve',
3 13:'thirteen', 14:'fourteen', 15:'fifteen', 16:'sixteen', 17:'seventeen', 18:'eighteen',19:'nineteen', 20:'twenty', 30:'thirty', 40:'forty', 50:'fifty', 60:'sixty',70:'seventy', 80:'eighty', 90:'ninety', 100:'hundred'}
4
5 #for i in range(1, 1001):
6 def gen_num(n, stack=[]):
7 if n == 0:
8 return stack
9 if n == 100:
10 return stack + ['one', 'hundred']
11 if n == 1000:
12 return stack + ['one', 'thousand']
13 if n in Len:
14 return stack + [Len[n]]
15 else:
16 if n>= 100:
17 a, b = divmod(n, 100)
18 if b != 0:
19 ret = stack+[Len[a]+'hundredand']
20 else:
21 ret = stack+[Len[a]+'hundred']
22 return gen_num(b, stack+ret)
23 elif n >= 10:
24 a, b = divmod(n, 10)
25 return gen_num(b, stack+[Len[a*10]])
26
27 lens = sum(sum(len(j) for j in gen_num(i)) for i in range(1, 1001))
28 print lens
29 #a = gen_num(342)
30 #print a, sum(len(j) for j in a)
31
32
33
Something went wrong with that request. Please try again.