1# sieve of Eratosthenes 2max = Integer(ARGV.shift || 100) 3sieve = [] 4for i in 2 .. max 5 sieve[i] = i 6end 7 8for i in 2 .. Math.sqrt(max) 9 next unless sieve[i] 10 (i*i).step(max, i) do |j| 11 sieve[j] = nil 12 end 13end 14puts sieve.compact.join(", ") 15