From: "email55555@..." Date: 2007-04-25T04:49:11+09:00 Subject: Re: Regexp and Prime numbers Cool! I couldn't resist porting it to Java, so here is my Java version (It is not one-liner, but maybe one statement?) : public class PrimeTester { public static void main(String[] args) { System.out.println(String.format("%0" + args[0] + "d", 0).matches("^0$|^(00+?)\\1+$") ? "Not prime" : "Prime"); } } http://davidtran.doublegifts.com/blog/?p=12 On Mar 19, 3:07 pm, "Tim Pease" wrote: > This is a one-liner Ruby script that will tell you if a given number isprime. > > 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 theregexp > works. > > http://montreal.pm.org/tech/neil_kandalgaonkar.shtml > > I highly recommend reading this if you want to flex yourregexpmuscles 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'tprime!