Although p: and q: have taken much of the fun out of writing prime number algorithms, I've always liked the following for testing for whether a number is prime:

[: =/ ] +. >:@i.@<[EMAIL PROTECTED]:

(This also seems to do what you'd expect for negative arguments.)

Mike Powell
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to