A random collection of things I come across.

Wednesday, September 26, 2007

Perl one-liner for testing prime numbers!


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.

No comments: