From: gotoken@... (GOTO Kentaro) Date: 2001-03-10T03:19:05+09:00 Subject: [ruby-talk:12346] Re: ...and the challenge In message "[ruby-talk:12344] Re: ...and the challenge" on 01/03/10, Mathieu Bouchard writes: > n=1_000_000 > nums=[] > (0..20).each{|a| > (0..13).each{|b| > (0..9).each{|c| > x = 2**a * 3**b * 5**c > nums << x if x <= n > } > } > } > nums.sort! > nums.each{|x|p x} > > >This takes 0.35 second here. > >matju 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 -- Gotoken