Skip to content

Instantly share code, notes, and snippets.

@jcasimir
Created April 9, 2013 15:49
Show Gist options
  • Save jcasimir/5346823 to your computer and use it in GitHub Desktop.
Save jcasimir/5346823 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