Skip to content

Instantly share code, notes, and snippets.

@GEEGABYTE1
Created August 30, 2021 20:53
Show Gist options
  • Save GEEGABYTE1/fccd8c0b9f98c739434978ec83c93ded to your computer and use it in GitHub Desktop.
Save GEEGABYTE1/fccd8c0b9f98c739434978ec83c93ded to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes - Base Implementation
def sieve_of_eratosthenes(limit):
true_indices = []
array = [i for i in range(2, limit + 1)]
dictionary = {}
for number in array:
dictionary[number] = True
for key, value in dictionary.items():
if value == False:
continue
else:
for number in dictionary.keys():
if number == key:
continue
elif number % key == 0:
dictionary[number] = False
else:
continue
for key, value in dictionary.items():
if value == True:
true_indices.append(key)
return true_indices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment