-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_017.py
More file actions
60 lines (56 loc) · 1.13 KB
/
Copy pathproblem_017.py
File metadata and controls
60 lines (56 loc) · 1.13 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
49
50
51
52
53
54
55
56
57
58
59
60
# Date: 2019.10.31
# Answer: 21124
import math
numbers = {1:"one",
2:"two",
3:"three",
4:"four",
5:"five",
6:"six",
7:"seven",
8:"eight",
9:"nine",
10:"ten",
11:"eleven",
12:"twelve",
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",
"hund":"hundred",
"and":"and",
"thou":"thousand"}
sum = 0
#a = 111
#print(len(numbers.get(1)))
# for i in range(a,a+1):
for i in range(1,1001):
if i % 100 < 20 and i % 100 > 0:
#print("0-20")
sum += len(numbers.get(i%100))
if i % 100 >= 20:
#print(">20 tens digit")
sum += len(numbers.get(math.floor(i%100 - i%10)))
if i % 100 >= 20 and i % 10 > 0:
sum += len(numbers.get(i%10))
if i >= 100 and i < 1000:
if i % 10 != 0 or i % 100 != 0:
sum += len(numbers.get("and"))
#print("hund")
sum += len(numbers.get(math.floor(i/100)))
sum += len(numbers.get("hund"))
if i > 999:
sum += len(numbers.get("thou"))
sum += len(numbers.get(1))
print(sum)