Last active
August 29, 2015 13:57
-
-
Save astronomy88/9635711 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
end_value = 120 | |
#-- Without using mod | |
b = Array(2..end_value) | |
primes = Array(2..end_value) | |
limit = Math.sqrt end_value | |
b.each do |z| | |
break if z >= limit | |
primes.each do |i| | |
break if (z*i) > b.last | |
next if i == 0 | |
primes[(z*i)-2] = 0 if primes[(z*i)-2] == (z * i) | |
end | |
end | |
primes.delete_if { |j| j == 0 } | |
puts "Sieve of erastothenes: #{primes}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment