Skip to content

Instantly share code, notes, and snippets.

@ficapy ficapy/
Last active Aug 29, 2015

What would you like to do?
from functools import partial
import math
remove = lambda x, comp: not (x > comp and not x % comp)
def primerlist(n):
assert isinstance(n, int)
assert n >= 4
arr = range(2, n + 1)
flag = 2
end = int(math.sqrt(n))
while True:
if flag > end:
arr = list(filter(partial(remove, comp=flag), arr))
flag = next(i for i in arr if i > flag)
return arr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.