|
|
| Welcome to the Monastery | |
| PerlMonks |
(tye)Re3: (Golf): Sieve of Eratosthenesby tye (Cardinal) |
| on May 20, 2001 at 01:56 UTC ( #81769=note: print w/ replies, xml ) | Need Help?? |
|
tilly's comment about things being "nearly linear" threw me for a bit. Then I realized that the quadratic nature is countered by the outer loop only needing to run to sqrt(N) and the inner loop being somewhat similarly restricted. Which made me realize that my solution was suboptimal. Here is a faster one at the same number of characters [ thanks to MeowChow noting that I'd stupidly left in a trailing semicolon in my previous one ;) ]:
In playing with this and verifying that I didn't break it, I noticed something interesting and expanded on it. For how long of a stretch can you go without hitting any prime numbers? Well, stopping at 0.5million (because of memory limits), here are the results. "xN" means there were N ties before a new "winner" appeared: - tye (but my friends call me "Tye")
In Section
Meditations
|
|
||||||||||||||||||||||||