Programming Challenge Numbers to Text?
plug.org at 2nerds.com
plug.org at 2nerds.com
Fri May 5 11:20:09 MDT 2006
On Thu, 4 May 2006, Troy Bowman wrote:
> I suck at C, but here's a stab at it...
>
> troy at azriel:~$ ./count 1 15 100 393 1938 91283 4918239 2147483647
> 1: one
> 15: fifteen
> 100: one hundred
> 393: three hundred ninety-three
> 1938: one thousand nine hundred thirty-eight
> 91283: ninety-one thousand two hundred eighty-three
> 4918239: four million nine hundred eighteen thousand two hundred thirty-nine
> 2147483647: two billion one hundred forty-seven million four hundred
> eighty-three thousand six hundred forty-seven
If this was a competition, and not merely exhibition, :-) lisp's
somewhat byzantine "~r" format directive might earn it a shot at
the prize:
This lisp expression:
(format t "~r~%~r~%~r~%~r~%~r~%" 1 15 91283 4918239 2147483647)
produces this output:
one
fifteen
ninety-one thousand, two hundred and eighty-three
four million, nine hundred and eighteen thousand, two hundred and thirty-nine
two billion, one hundred and forty-seven million, four hundred and eighty-three thousand, six hundred and forty-seven
(The "~%" format directive is similar to "\n".)
:-)
Chris
More information about the PLUG
mailing list