Thanks for your time reading this.
I’ve been working on this problem 10 for the last couple days and i’ve been trying to improve runtime and not have it take over half an hour to an hour to run. At first it was horrible checking each value if prime and removing, then i discovered Sieve of Eratosthenes and have tried implementing it. I’m unsure if I’m even making an improvement here.
goal = 2000000
allBelow = [int(x) for x in range(0,goal)]
def sieveOut(lst:list,value:int):
index = lst.index(value)
while index < len(lst):
v=lst[index]
if v != value and v%value == 0:
print("REMOVING: " + str(v))
lst.remove(v)
index+=value
return lst
index = 0
allBelowLength = len(allBelow)
while index < allBelowLength:
value = allBelow[index]
if value <= 1:
print("Removing " + str(value))
allBelow.remove(value)
else:
print("Sieving out " + str(value))
allBelow = sieveOut(allBelow,value)
index += 1
allBelowLength = len(allBelow)
print(str(allBelow) + " :: " + str(sum(allBelow)))