Here’s a coding problem for those that like this kind of thing. Let’s see your implementations (in your language of choice, of course) of a function which returns a human readable String representation of a specified Integer. For example:
- humanReadable(1) returns ‘one’.
- humanReadable(53) returns ‘fifty-three’.
- humanReadable(723603) returns ‘seven hundred and twenty-three thousand, six hundred and three’.
- humanReadable(1456376562) returns ‘one billion, four hundred and fifty-six million, three hundred and seventy-six thousand, five hundred and sixty-two’.
Bonus points for particularly clever/elegant solutions!
It might seem like a pointless exercise, but there are number of real world applications for this kind of algorithm (although supporting numbers as high as a billion may be overkill 🙂
There was already a question about this: Convert integers to written numbers
The answer is for C#, but I think you can figure it out.