in reply to Sieve of Eratosthenes Golf?

My first solution, in which I explicitly include the number 100, is at 85 characters, to be run with perl -l.

for(2..100){$n{$y=$_}&&next;$n{$y+=$_}=1 while($_+$y)<=100}for(2..100){$n{$_}||print}

More^WLess to come, I hope.

Replies are listed 'Best First'.
Re^2: Sieve of Eratosthenes Golf?
by cog (Parson) on Apr 07, 2005 at 09:57 UTC
    OK, I know I'm twisting things a little, but I don't consider the problem to be well formed anyway (what is the objective? to print all the prime numbers between 2 and 100? to implement the sieve of Erathosthenes? in a sub? with which output?)

    Anyway, here's a basic enhancement, and I also trimmed two characters with s/100/99/ (hey, we all know 100 is not prime, right? O:-) )

    for(2..99){$n{$y=$_}&&next;$n{$y+=$_}=1 while($_+$y)<=99;$n{$_}||print

    I'm now at 71 chars.

      strict and warnings compliant at 77 characters ...
      $_{$.=$_}||do{{($_{$.+=$_}=$.+$_<=$,)&&redo}}for@.=2..($,=pop);grep!$_ +{$_},@.