class Primos::Primos

@author Chiara Piccinini Núñez

Public Class Methods

new(number) click to toggle source

Find all the prime numbers minor than another natural number. @param [Integer] The limit to stop the searching.

# File lib/primos/primos.rb, line 7
def initialize number
    @number = number
    p = 2
    @ps = []
    while p < number
        pr = true
        @ps.each do |x|
            if p % x == 0
                pr = false
                break
            end
        end
        if pr
            @ps << p
            puts "#{p} <= #{@ps.count} ✓"
        end
        p+= 1
    end
    self.print
end

Public Instance Methods

print() click to toggle source

Print the quantity of primes that been found and the limit.