Project Euler 7(Ruby 1.012031s)
require "benchmark" def is_prime(k) prime = [] total = [] for i in 0..k prime << 1 end q = Math.sqrt(k).to_i for i in 2..q if prime[i] == 1 for j in 2*i..k if j % i == 0 prime[j] = 0 end end end end for i in 2..k if prime[i] == 1 total << i end end return total end puts Benchmark::CAPTION puts Benchmark.measure{ p is_prime(110000)[10000] }