I am currently going through all of the algorithms we learned about in a certain class, trying to understand what each does and how. However, I am a bit clueless about a certain line in our Eratosthenes sieve:
def sieve(n):
primes = [] # list
is_prime = [False,False]+[True]*(n-1) # how does a list [false,false,true,true....] do anything?
for p in range(2,n+1): #number from 2 to n
if is_prime[p]: #how does this same list finds out if it is a prime number?
primes.append(p) # adds p the list
for i in range(p**2,n+1,p): # goes from the square of p to n, in p long steps
is_prime[i]=False # those found obviously aren't prime
print(primes) # prints the list
This is a really simple algorithm, its base function works on something that I do not understand, so that is a bit of a problem. Someone please explain to me what it does, thank you.