From: Siep Korteling Date: 2007-11-06T20:14:56+09:00 Subject: sieve.rb sample the sieve of Erathotenes sample (sieve.rb) in Ruby 1.9 looks like this: max = Integer(ARGV.shift || 100) sieve = [] for i in 2 .. max sieve[i] = i end for i in 2 .. Math.sqrt(max) next unless sieve[i] (i*i).step(max, i) do |j| sieve[j] = nil end end puts sieve.compact.join(", ") Is Math.sqrt(max) calculated every loop? .... m=Math.sqrt(max) for i in 2 .. m .... runs about 20% faster on my machine. -- Posted via http://www.ruby-forum.com/.