in reply to Prime number generator

Hi jimt,

Here's a 23-character script that, for any integer input, will output a prime number:

$_=$=-(shift)**$[;print

Okay, maybe that's cheating ... :-)

Here's a prime-number generator in 65 characters.  I wouldn't be surprised if it can be golfed further...

$o=1;{++$o&&grep{$o/$_==int$o/$_}keys%_ or$_{$o}=print$o.$/;redo}

Update:  Make that 64 characters...

$o=1;{++$o&&grep$o/$_==int$o/$_,keys%_ or$_{$o}=print$o.$/;redo}

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: Prime number generator
by Ieronim (Friar) on Jul 17, 2006 at 19:38 UTC
    ..and even 57:
    $o=1;{++$o&&grep!($o%$_),keys%_ or$_{$o}=print$o.$/;redo}

         s;;Just-me-not-h-Ni-m-P-Ni-lm-I-ar-O-Ni;;tr?IerONim-?HAcker ?d;print
      Very slick! ++

      It looks even nicer, I think, without whitespace, though I can't find a way to improve on your 57 ... yet! ...

      $o=1;{$_{$o}=print$o.$/if++$o&&!grep!($o%$_),keys%_;redo}

      Update:  Aha!  It took me some thinking, but here's 56 ...

      $o=1;{$_{$o}=print$o.$/if++$o,!grep!($o%$_),keys%_;redo}

      s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
        And this is 54 :)
        $o=1;{print$_[0+@_]=$o.$/if++$o,!grep!($o%$_),@_;redo}

             s;;Just-me-not-h-Ni-m-P-Ni-lm-I-ar-O-Ni;;tr?IerONim-?HAcker ?d;print