diff --git a/Algorithms.py b/Algorithms.py index 0a28a63..f13fb65 100644 --- a/Algorithms.py +++ b/Algorithms.py @@ -22,6 +22,7 @@ Copyright (C) 2019 Matthew Ellison import math +import itertools #Generate an infinite sequence of prime numbers using the Sieve of Eratosthenes @@ -33,9 +34,8 @@ def primeGenerator(): #Map composite integers to primes witnessing their compositeness dict = {} - #Start checking for primes with the number 3 - possiblePrime = 3 - while True: + #Start checking for primes with the number 3 and skip all even numbers + for possiblePrime in itertools.count(3, 2): #If q is not in the dictionary it is a new prime number #Return it and mark it's next multiple if possiblePrime not in dict: @@ -49,9 +49,6 @@ def primeGenerator(): #We no longer need this, free the memory del dict[possiblePrime] - #Skip all multiples of 2 - possiblePrime += 2 - #Generate an inifinite sequence of fibonacci numbers def fibGenerator(): #Set this so the first returned number is 1 and the second is also 1