Commit 9d6f3c1a authored by Michael Krause's avatar Michael Krause 🎉
Browse files

Add prime sequence (sieve)

parent ce64f872
......@@ -11,3 +11,22 @@ def fibonacci(n):
def naturalsquares(n):
return [x**2 for x in range(n)]
def primes(n):
"""return first n primes"""
nn = n**2
mask = []
for i in range(nn):
for i in range(2, int(math.floor(math.sqrt(nn)))):
if mask[i]:
j = i**2
while j < nn:
mask[j] = False
j += i
primes = []
for i in range(nn):
if mask[i]:
return primes[0:n]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment