perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/' [number]
See http://montreal.pm.org/tech/neil_kandalgaonkar.shtml for an explanation
of how it works. It basically involves backtracking.
A random collection of things I come across.
Wednesday, September 26, 2007
Perl one-liner for testing prime numbers!
Posted by Prashanth. at 11:07 AM
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment