From: Tim Pease Date: 2007-03-20T04:07:03+09:00 Subject: Regexp and Prime numbers This is a one-liner Ruby script that will tell you if a given number is prime. ruby -wle 'puts "Prime" unless ("1" * ARGV[0].to_i) =~ /^1$|^(11+?)\1+$/' [number] I cannot take credit for this one -- it originally came from Perl. The website listed below gives the full explanation of how the regexp works. http://montreal.pm.org/tech/neil_kandalgaonkar.shtml I highly recommend reading this if you want to flex your regexp muscles today. Blessings, TwP ruby -wle 'puts "Prime" unless ("1" * ARGV[0].to_i) =~ /^1$|^(11+?)\1+$/' 42 It may be the answer to life, the universe, and everything, but it certainly isn't prime!