Created
August 30, 2021 20:53
-
-
Save GEEGABYTE1/fccd8c0b9f98c739434978ec83c93ded to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes - Base Implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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