Project Euler problem 17 turned out to be quite an easy one.
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
The solution this time is almost trivial:
"Zero" is considered to have 0 length (it will be obvious later on why this is the case)
Numbers from 1 to 19 have their own unique names (i.e. they are not composed by putting together more words)
Numbers from 20 to 99 are combined putting together a word like "thirty" and a number from 0 to 9. If the number is zero, we don't add anything (we don't say "twenty and zero")
Numbers from 100 to 999 are combined putting together a words like "two hundred and" plus a number from 0 to 99 composed as explained above. Exact multiples of 100 are exception in that they don't have another trailing number (again, we don't say "two hundred and zero").
Your first encounter with GIT as a version control tool may be quite intimidating, especially if all you had been using so far was something simpler like Sub...
Today I was debugging some interaction between one of our products and Twitter 1.1 API protected by OAuth 1.0a . As it happens, I was using Fiddler to have a...
Antonio Vidal has translated this post into Spanish: you can find it
here.
Dependency injection is a very simple concept: if you have an object that interac...
Building Reduce and Map from the Ground Up with F#
Today I've found myself reading again the excellent paper
Why Functional Programming
Matters, where ...
Leave a Comment