Project Euler #58: Spiral Primes

This one is interesting because it's relatively simple to program but if you don't optimize it, it can time out even with a powerful language. This Julia code returned the correct answer in about 3 seconds:



However, putting s=0 in the while loop INSTEAD of letting s be global, and replacing for "for l in L" with "for d in D", gives a program that won't halt even in 10 minutes. For my program, those two minor changes in Julia made all the difference.

Ans.: 26241

Comments