More tests for the generators.

This commit is contained in:
Cédric Bonhomme 2017-03-09 08:54:13 +01:00
parent 0da9d9882e
commit 7c9530aa9d
No known key found for this signature in database
GPG key ID: A1CB94DE57B7A70D
3 changed files with 51 additions and 28 deletions

View file

@ -73,7 +73,8 @@ def mersenne() -> Iterator[int]:
y = 2*y + 1
def eratosthenes() -> Iterator[int]:
"""Generate the prime numbers with the sieve of Eratosthenes.
"""https://oeis.org/A000040
Generate the prime numbers with the sieve of Eratosthenes.
"""
d = {} # type: dict[int, int]
for i in itertools.count(2):
@ -85,8 +86,9 @@ def eratosthenes() -> Iterator[int]:
d[i * i] = [i]
yield i
def eratosthenes_composite() -> Iterator[int]:
"""Generate the composite numbers with the sieve of Eratosthenes.
def composite() -> Iterator[int]:
"""https://oeis.org/A002808
Generate the composite numbers using the sieve of Eratosthenes.
"""
p1 = 3
for p2 in eratosthenes():