cat posts/2010-07-21-regular-expression-to-check-for-primes.md

Regular Expression to check for primes

· 1 min read

// archive Originally published on my old blog, indiangeek.net, in 2010. Links and opinions may have aged.

perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/' [number]

via montreal.pm.org

This is a nice trick to check if a number is prime using regular expressions, I am going to try and see how this performs compared to regular methods and see if anything interesting comes up.

Posted via email from Sijin Joseph