Skip to content

Instantly share code, notes, and snippets.

@BarnabasMarkus
Created August 5, 2016 16:32
Show Gist options
  • Save BarnabasMarkus/6516cbaed9e91a9b71dcbaa7f22d67b3 to your computer and use it in GitHub Desktop.
Save BarnabasMarkus/6516cbaed9e91a9b71dcbaa7f22d67b3 to your computer and use it in GitHub Desktop.
sieve of eratosthenes // find primes algorithm
#!/usr/bin/env python3
# S I E V E O F E R A T O S T H E N E S
# Project Sieve of Eratosthenes Prime Finder
# Author Barnabas Markus
# Email barnabasmarkus@gmail.com
# Date 05.08.2016
# Python 3.5.1
# License MIT
from math import sqrt
def sieve(n=100):
lst = [x for x in range(0, n+1)]
lst[1] = 0
limit = int(sqrt(n)) + 1
for i in range(2, limit):
if lst[i] == 0:
continue
for j in range(i*2, len(lst), i):
if lst[j] != 0:
lst[j] = 0
return [i for i in lst if i != 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment