The following code takes a positive integer command-line argument (<306) and tests to see if it is prime. In a very, very, silly way.
eval or exit print "$n is not prime.\n" for <@{$"=',',[$n=pop]}-1/(1${\("/{@{[2..1+$n/2]}}"x2)})|0>,' print "$n is prime.\n"'

Edit:Modified code with |0 to stop it claiming 98 was prime.

Replies are listed 'Best First'.
Re: Testing for prime-ness, the silly way
by hopes (Friar) on Sep 28, 2002 at 15:01 UTC