|
|
| Keep It Simple, Stupid | |
| PerlMonks |
(tye)Re: (Golf): Sieve of Eratosthenesby tye (Cardinal) |
| on May 19, 2001 at 12:00 UTC ( #81697=note: print w/ replies, xml ) | Need Help?? |
|
Though I somehow doubt this is a winner, I think it might qualify for the "bonus marks". You'll note that no division (or modulus) is used, so I consider it to be using the sieve with no special cases or wasted operations (though it probably has plenty of wasted comparisons O-:). Though it might be more efficient to break out of the grep when a non-prime is found (or, if we had things in a sorted order, to stop once $_*$_ passes $n) and compensate for that by incrementing $p{$_} in an extra loop (rather than incrementing it, at most, one time per prime candidate), but I'm not even sure if that would be a net win (without resorting to sorting).
I count 86 characters for the part that counts. And, no, I don't think it'd be fair to add 13 characters for sorting since the original challange didn't say anything about returning the list in sorted order. q-: Sample output:
Update: BTW, this is strict compliant. - tye (but my friends call me "Tye")
In Section
Meditations
|
|
||||||||||||||||||||||||||||||