From charlesreid1

Revision as of 03:02, 5 July 2017 by Admin (talk | contribs)

Problem 17 deals with the number of letters it takes to spell out a number.

First, let it be said that this is a problem that shows how tremendously awful language rules can be, when contrasted with the happy certainty of mathematics.

This basically requires about 20 special cases, and from there things are relatively smooth. This program only goes up to 1,000, but it would be entirely plausible to extend this program to go even further and handle extremely large numbers in a more programmatic way.

Much like this problem, the larger the digits go, the more digits you can name with a single, systematic rules.

Consider, for example: the first 20 digits require 20 rules. But once we reach twenty one, we have a twenty-first rule that covers the next 9 numbers. (Take "twenty" and add the spelling of any nonzero number in the ones place, which doesn't require any new rules). Next, we get to thirty, and require a new label "thirty" but the same rule - add the spelling of any nonzero number in the ones place, thirty one, thirty two, thirty three, etc. Now, just a few rules can generalize and take us all the way to 99. That's eight new rules ("twenty", "thirty", "forty", and so on) to cover 80 additional numbers. Whew!

Once we get to the hundreds, we can name way more numbers - one additional rule (introducing the word "hundred") takes us all the way to 999. One more rule ("thousand") takes us to 999,999 new numbers. And now the system becomes more refined - all the special cases were all piled up at the very beginning.