# Project Euler 17

• 問題

Problem 17：Number letter counts
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?

• 解答例
```figure = {  0:"",
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",
100:"hundred",
1000:"onethousand"}

def num2wordLen(num):
l = 0
# 1000の処理
if num == 1000:
l += len(figure[1000])
return l
# 100〜999の処理
q100 = num // 100
r100 = num % 100
if(q100 > 0):
l += (len(figure[100]) + len(figure[q100]))
# and処理
if(r100 != 0):
l += 3
# 1〜99の処理
if(r100 < 20):
l += len(figure[r100])
else:
q10 = r100 // 10
r10 = r100 % 10
l += (len(figure[q10 * 10]) + len(figure[r10]))
return l

count = 0
for i in range(1, 1001):
count += num2wordLen(i)

print(count)
```