The clouds have parted (even though it's storming here right now) and allowed me to briefly glimpse the mind of god. It is an ugly beast that takes nearly a minute to solve this simple(ish) problem, and does not lend itself easily to more complex operations, but it works for what I needed it for (to advance and increase my genius rating mwah ha ha!). Thanks for helping me solve
Project Euler #10 god. Your aid will soon be forgotten, my increased genius ranking however, will not.
#!/usr/bin/env python
#euler10.py
#Calculate the sum of all primes below 2,000,000
def main():
Primes = [2]
n = 2
sum = 2
for i in range(3, 2000000):
while i % n != 0 and n <= 2001:
n += 1
if n == i or n > 2000:
Primes.append(i)
sum += i
else:
n = 2
print sum
if __name__ == '__main__':
main()
No comments:
Post a Comment