Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Wow... and I was happy with:

    sub mystery{for($t=3;$t*$t<$_[0];$t+=2){if(!$c[$t]){for($s=$t*$t;$s<$_[0];$s+=$t*2)
    {$c[$s]++}}}$r[++$#r]='2';for($t=3;$t<$_[0];$t+=2){$c[$t]||push(@r,$t)}return(@r)};
(Based on http://www.c2.com/cgi/wiki?SieveOfEratosthenesInManyProgramm... but with a fun push alternative and in function form)


Any time you see a three arg for loop in perl golf, it's probably Doing It Wrong.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: