On Saturday 10 March 2001 18:15, you wrote:
> On Sat, 10 Mar 2001, GOTO Kentaro wrote:
> > >This takes 0.35 second here.
> >
> > On my machine, yours takes 1.15 sec.
> > The following takes 0.55 sec here.
>
> Ok, I also had written the following one. How long does it take over
> there? it takes more time to initialize the ruby interpreter, and it takes
> more time to print the numbers than to generate them...
>
>         nums=[]
>         def foo(x,y,n); while y<=n; yield y; y *= x; end; end
>         foo(2,1,n) {|a| foo(3,a,n) {|b| foo(5,b,n) {|c| nums << c }}}
>         nums.sort!
>         for x in nums do p x end
>
> (oh, btw. Ben's version takes over 3 times longer. i'm now testing with
> n=10**30 and using >/dev/null)
>
> matju

Here's a rewrite of Ben's version that takes about 2 times longer.  I was
wondering if the class overhead was too much.  Guess not.  It looks like
trading Array.sort! for more accounting is a good trade

generators = [2, 3, 5]
vals = generators.dup
pos = Array.new (generators.length, 0)

max = ARGV[0].to_i

# Need elements 0 and 1
seq = [1, generators.min]
p seq[0]

min_val = vals.min
while min_val <= max
    p min_val

    vals.each_index do |i|
        if min_val == vals[i]
            pos[i] += 1
            vals[i] = generators[i] * seq[pos[i]]
        end
    end

    min_val = vals.min
    seq.push min_val

end

puts "Done"

-John Moore