From: Kevin Smith Date: 2001-03-10T12:19:03+09:00 Subject: [ruby-talk:12367] Re: ...and the challenge gotoken@math.sci.hokudai.ac.jp wrote: >On my machine, yours takes 1.15 sec. >The following takes 0.55 sec here. > > n=1_000_000 > nums=[] > for a in 0..20 > a0 = 2**a > for b in 0..13 > b0 = 3**b > for c in 0..9 > x = a0 * b0 * 5**c > nums.push x if x <= n > end > end > end > nums.sort! > for x in nums do p x end Pure speculation: Could we speed it up a bit by breaking out of each loop (or at least the innermost loop) after "n" was exceeded? If so, it would probably be even faster to loop by 9, 13, 20 instead of 20, 13, 9. Of course, speed isn't everything. Kudos for creating this code which is clean and straightforward! Kevin