exercism/ruby/sieve/sieve.rb

19 lines
261 B
Ruby
Raw Normal View History

2018-03-02 22:27:55 +00:00
class Sieve
def initialize(base)
@num = base
end
def primes
2018-03-09 20:13:37 +00:00
(2..Math.sqrt(@num)).each_with_object([nil, nil, *2..@num]) do |p, res|
(p*p).step(@num, p) { |m| res[m] = nil }
end.compact
2018-03-02 22:27:55 +00:00
end
end
module BookKeeping
VERSION = 1
end
2018-03-09 20:13:37 +00:00