Title / Description
Code def sieve_of_eratosthenes(max_prime) sieve = Array.new(max_prime, true) sieve[0] = sieve[1] = false 2.upto(Math.sqrt(max_prime)) do |i| if sieve[i] (i**2).step(max_prime, i) do |j| sieve[j] = false end end end result = [] sieve.each_index do |i| result << i if sieve[i] end return result end
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code