From: Kevin Smith Date: 2000-12-21T05:31:40+09:00 Subject: [ruby-talk:7793] Re: Next amusing problem: talking integers >Meanwhile -- well, am I allowed to do the cowardly thing, and >pose this as a puzzle, without actually having done it yet? I did >do it in Perl, but am curious to see ideas for it in Ruby. > >Namely...... > >Input: 123456 >Output: "one-hundred twenty-three thousand four-hundred fifty-six" > >etc. My first shot at a Ruby solution can be viewed at: www.qualitycode.com/towords.rb I decided to handle negative numbers reasonably, and with a range into the trillions. I also changed the problem definition slightly, to avoid dashes in 'one-hundred' but to keep them in 'twenty-three' (because that's how I learned it in school). And I put commas between billions, millions, thousands, etc. I make absolutely no claims about performance. My goal was to get it working quickly, and to have simple, maintainable code. If I spent more time on it, I would probably try to do it as a Module/mix-in (a feature I haven't played with yet). Kevin