On Thu, 21 Dec 2000, Kevin Smith wrote: > Dan Schmidt <dfan / harmonixmusic.com> wrote: > >David Alan Black <dblack / candle.superlink.net> writes: > > > >| Input: 123456 > >| Output: "one-hundred twenty-three thousand four-hundred fifty-six" > > > >I don't like hyphens, but it would be easy enough to put them in: > > > >def english_num (num) > > ones_names = '.one.two.three.four.five.six.seven.eight.nine.ten.eleven.twelve.thirteen.fourteen.fifteen.sixteen.seventeen.eighteen.nineteen'.split('.') > > Nice way to set up an array of strings. I'll > borrow it. It beats ['', 'one', 'two'...]. Also, Well, it depends what you mean by "beat" :-) require 'benchmark' include Benchmark bm do |x| x.report { 100000.times do a = ['', 'one', 'two', 'three', 'four', ........ ] end } x.report { 100000.times do a = '.one.two.three.four..........'.split '.' end } # Here's another possibility: x.report { 100000.times do a = %w{one two three four .........'}.unshift '' end } end # 100000 iterations on my trusty Pentium 200: user system total real 6.890000 0.000000 6.890000 ( 6.897994) 17.920000 0.000000 17.920000 ( 17.925662) 9.810000 0.000000 9.810000 ( 9.811511) It's hard to imagine circumstances where you'd be running tens of thousands of these at a time, but anyway.... Seeing the various solutions is cool. I didn't quite find time to write one today, and I think I may have been rendered redundant. (The Tom Sawyer approach to code generation :-) David -- David Alan Black home: dblack / candle.superlink.net work: blackdav / shu.edu Web: http://pirate.shu.edu/~blackdav