-
Notifications
You must be signed in to change notification settings - Fork 0
/
euler17.py
49 lines (45 loc) · 996 Bytes
/
euler17.py
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
49
belowTwenties = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen"]
tens = ["twenty", "thirty", "forty", "fifty",
"sixty", "seventy", "eighty", "ninety"]
hundred = "hundred"
thousand = "thousand"
def getLength(n):
text = ""
while(n > 0):
if n == 1000:
text = "Onethousand"
break
elif n >= 100:
rest = n % 100
text += belowTwenties[(n - rest) // 100] + \
hundred + ("and" if rest > 0 else "")
n = rest
elif n >= 20:
rest = n % 10
text += tens[(n - rest) // 10 - 2]
n = rest
elif n > 0:
text += belowTwenties[n]
n = 0
return len(text)
print(sum([getLength(x) for x in range(1, 1001)]))