Module: MissingMath
- Defined in:
- lib/missing_math.rb,
lib/missing_math/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
-
.esieve(n) ⇒ Object
Generates a prime sieve with max value n Example: MissingMath.esieve(1000) => [2, 3, 5, …].
Class Method Details
.esieve(n) ⇒ Object
Generates a prime sieve with max value n Example: MissingMath.esieve(1000) => [2, 3, 5, …]
174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/missing_math.rb', line 174 def self.esieve(n) a = (0..n).to_a a[0] = nil a[1] = nil a.each do |i| next unless i break if i * i > n (i * i).step(n, i) { |m| a[m] = nil} end return a.compact end |