Neatened primeGenerator

This commit is contained in:
2021-03-11 16:05:39 -05:00
parent 74b3c629b7
commit 004dee57cc

View File

@@ -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