Class: PrimeNumbers::AlgorithmOneLiner
- Inherits:
-
Object
- Object
- PrimeNumbers::AlgorithmOneLiner
- 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 = [] (a..b).each do |number| << number if self.is_prime? number end end |
#is_prime?(number) ⇒ 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 |