Class: Prime8::Strategies::Strategy

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/prime_8/strategies/strategy.rb

Instance Method Summary collapse

Constructor Details

#initializeStrategy

Returns a new instance of Strategy.



5
6
7
8
# File 'lib/prime_8/strategies/strategy.rb', line 5

def initialize
  @primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
  @max_checked = @primes.last + 1
end

Instance Method Details

#get_nth_prime(n) ⇒ Object



10
11
12
13
# File 'lib/prime_8/strategies/strategy.rb', line 10

def get_nth_prime(n)
  compute_primes while @primes.size <= n
  @primes[n]
end

#get_through_nth_prime(n) ⇒ Object



15
16
17
18
# File 'lib/prime_8/strategies/strategy.rb', line 15

def get_through_nth_prime(n)
  compute_primes while @primes.size <= n
  @primes.first(n)
end