Ejemplo n.º 1
0
def generate_primes_to_n(n):
    known_primes = primes.load_pickled_primes()
    ps = primes.generate_primes(n)
    if len(ps) > len(known_primes):
        known_primes = ps
    f.write("----------------------------------------\n")
    f.write("Date: " + time.strftime('%m-%d-%Y @ %H:%M') + "\n")
    f.write("Number of primes generated = %d \n" % (len(ps)))
    f.write("Highest prime in primes.pickle = %d \n" % (known_primes[-1]))
    f.write("Number of  primes in primes.pickle = %d \n\n\n" % (len(known_primes)))
    f.flush()
    primes.pickle_primes(ps)
    f.flush()
    f.close()
    return ps
Ejemplo n.º 2
0
    def initialize_primes(self, max_primes=10000000):
        """Generates an initial list of primes using primes.generate_primes(n)

        Args:
          f: File to log info about primes, which for now is just the total number
             or primes.

        Returns: List of primes self.known_primes_

        Raises: nothing  
        """
        self.max_primes_ = max_primes
        self.next_prime_ = 0 # set this back to the beginning of the list

        self.logger_.plog("Initialize primes to %s \n" % (max_primes))
        # our object then builds an array of all the known primes up to max_primes
        self.known_primes_ = primes.generate_primes(max_primes)
        primes.pickle_primes(self.known_primes_)
        self.logger_.plog("Primes found: " + str(len(self.known_primes_)) + "\n")
        return self.known_primes_