Class: PrimeNumbers::AlgorithmOneLiner

Inherits:
Object
  • Object
show all
Defined in:
lib/prime-numbers/algorithms/one_liner.rb

Instance Method Summary collapse

Instance Method Details

#generate(a, b) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/prime-numbers/algorithms/one_liner.rb', line 3

def generate a, b
  primenumbers = []
  (a..b).each do |number|
    primenumbers << number if self.is_prime? number
  end
  primenumbers
end

#is_prime?(number) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/prime-numbers/algorithms/one_liner.rb', line 11

def is_prime? number
  number < 2 ? false : ('1' * number) !~ /^1?$|^(11+?)\1+$/
end