Skip to content

Instantly share code, notes, and snippets.

@garciadanny
Forked from jcasimir/sieve.rb
Created April 9, 2013 15:50
Show Gist options
  • Save garciadanny/5346838 to your computer and use it in GitHub Desktop.
Save garciadanny/5346838 to your computer and use it in GitHub Desktop.
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