Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Regexp and Prime numbers
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tim Pease  
View profile  
 More options Mar 19 2007, 3:07 pm
From: "Tim Pease" <tim.pe...@gmail.com>
Date: Tue, 20 Mar 2007 04:07:03 +0900
Local: Mon, Mar 19 2007 3:07 pm
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!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Pease  
View profile  
 More options Mar 20 2007, 10:17 am
From: "Tim Pease" <tim.pe...@gmail.com>
Date: Tue, 20 Mar 2007 23:17:39 +0900
Local: Tues, Mar 20 2007 10:17 am
Subject: Re: Regexp and Prime numbers
On 3/20/07, gga <GGarram...@aol.com> wrote:

Now that is very interesting.  Do you know if Ruby 1.9 is running
Onigurma <sp?>, the new regexp handler?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Roelofs  
View profile  
 More options Mar 20 2007, 10:30 am
From: "Jason Roelofs" <jameskil...@gmail.com>
Date: Tue, 20 Mar 2007 23:30:05 +0900
Local: Tues, Mar 20 2007 10:30 am
Subject: Re: Regexp and Prime numbers

On 3/20/07, Tim Pease <tim.pe...@gmail.com> wrote:

For those of us on Windows command line:

ruby -wle "puts 'Prime' unless ('1' * ARGV[0].to_i) =~ /^1$|^(11+?)\1+$/"

That's cool.

Jason


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Edward Gray II  
View profile  
 More options Mar 26 2007, 1:45 pm
From: James Edward Gray II <ja...@grayproductions.net>
Date: Tue, 27 Mar 2007 02:45:22 +0900
Local: Mon, Mar 26 2007 1:45 pm
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
email55555@gmail.com  
View profile  
 More options Apr 24 2007, 3:49 pm
From: "email55...@gmail.com" <email55...@gmail.com>
Date: Wed, 25 Apr 2007 04:49:11 +0900
Local: Tues, Apr 24 2007 3:49 pm
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" <tim.pe...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »