-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17.py
54 lines (52 loc) · 1.22 KB
/
17.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
50
51
52
53
54
letters = [
("one", 1),
("two", 2),
("three", 3),
("four", 4),
("five", 5),
("six", 6),
("seven", 7),
("eight", 8),
("nine", 9),
("ten", 10),
("eleven", 11),
("twelve", 12),
("thirteen", 13),
("fourteen", 14),
("fifteen", 15),
("sixteen", 16),
("seventeen", 17),
("eighteen", 18),
("nineteen", 19),
("twenty", 20),
("thirty", 30),
("forty", 40),
("fifty", 50),
("sixty", 60),
("seventy", 70),
("eighty", 80),
("ninety", 90),
("onehundred", 100),
("twohundred", 200),
("threehundred", 300),
("fourhundred", 400),
("fivehundred", 500),
("sixhundred", 600),
("sevenhundred", 700),
("eighthundred", 800),
("ninehundred", 900),
("onethousand", 1000),
]
def count_letters(low: int, high: int) -> int:
count = 0
for i in range(low, high+1):
remainder = i
while remainder != 0:
for name, val in reversed(letters):
if remainder // val == 1:
remainder -= val
if remainder and val >= 100:
count += len("and")
count += len(name)
return count
print(count_letters(1, 1000))