-
-
Save garciadanny/5346838 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Sieve | |
attr_reader :values | |
def initialize(max) | |
@values = (2..max).to_a | |
end | |
def primes | |
values.each do |value| | |
puts "Filtering multiples of #{value} from #{values.inspect}" | |
remove_multiples_of(value) | |
end | |
return values | |
end | |
def remove_multiples_of(value) | |
@values = values.select{|v| (v % value != 0) || v == value} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment