-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem17.py
More file actions
24 lines (16 loc) · 948 Bytes
/
problem17.py
File metadata and controls
24 lines (16 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/python
from tools.timeit import timeit
from pprint import pprint as pp
from tools.general import num2words
problem = """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?
NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage."""
@timeit
def process():
result = [num2words(x) for x in range(1, 1001)]
result = "".join(result).replace(" ", "")
value = len(result)
return value
etime, solution = process()
print "Problem :\n%s\n\n\nSolution : %s" % (problem, solution)
print "\nRunning time : %10.6f seconds" % (etime)