|There's more than one way to do things|
Re: (Golf): Sieve of Eratosthenesby Arguile (Hermit)
|on May 19, 2001 at 16:14 UTC||Need Help??|
Well, looking through tilly's previous golf entries I think I'll feel fine if length($my_code) <= 3*length($tilly_code).
As for the lenght:
True to the seive, it starts at k=2 eleminates n*k, then steps to next prime and repeats until k >= sqrt(n). Instead of mapping to 0 I would have loved to just drop them -- not bothering w/ the regexp for cleanup -- but I couldn't for the life of me figure out how.
The subroutine is recursive mainly b/c I had yet to try that technique and this seemed like a good time to try.
Thanks to Petruchio for his rewording of ($k,@_)=($#_)?@_:2..($n=@_) so I didn't produce an error. So far this seems like a great place to learn programming.</fawning>
Scratched recursion and went w/ a conventional for loop, brought it down to 87 chars w/ strict compliance.
UpdateNo one else was mapping, and now I see why (75 chars).