PyPE solution to PE problem 17
PyPE solution to PE problem 17
Blueprint information
- Status:
- Complete
- Approver:
- None
- Priority:
- Undefined
- Drafter:
- None
- Direction:
- Needs approval
- Assignee:
- None
- Definition:
- Approved
- Series goal:
- None
- Implementation:
- Implemented
- Milestone target:
- None
- Started by
- Scott Armitage
- Completed by
- Scott Armitage
Whiteboard
ProjectEule
===
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.
Solution
--------
We begin with a dictionary containing the spelling for all numerals 1-19, as
well as all of the decades twenty through ninety. Any number less than 100
and greater than 19 can be composited from one decade and either zero or one
numerals. All numbers greater than or equal to 100 can be represented by their
two-digit counterparts, plus "[n] hundred and".
Answer
------
21124