From: James Edward Gray II Date: 2007-03-27T02:45:22+09:00 Subject: Re: Regexp and Prime numbers On Mar 19, 2007, at 2:07 PM, Tim Pease wrote: > 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. Wow, that was just awesome. James Edward Gray II