[Athens-pm] Regular expression for testing prime numbers

Philip Lees pjlees at ics.forth.gr
Fri Jan 17 06:39:57 CST 2003


Hello, fellow Perlers. Check out this amazing one liner for checking
whether a number is prime. It took me an hour before I even started to
understand it:

print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/

This is by Abigail, who is something of a legend in the Perl community.

Philip
--
Philip Lees
Working Group on Cardiology
ICS-FORTH, Science and Technology Park of Crete
Vassilika Vouton, P.O. Box 1385, GR 711 10 Heraklion, Crete, GREECE

tel.: +30-2810-391680, fax: +30-2810-391601, e-mail: pjlees at ics.forth.gr

'The aim of high technology should be to simplify, not complicate' -
Hans Christian von Baeyer 




More information about the Athens-pm mailing list