Try this , for Activestate Perl/W2K
perl -e "foreach $i (2..shift||1e2){ print \"$i \" unless (9x$i) =~ 
/^(99+)\1+$/ } " 100


>
>it didn't print anything out on my machine. :-(
>
>W2K, Activestate Perl 5.6.1 build 633
>
>-----Original Message-----
>From: Tanton Gibbs [mailto:[EMAIL PROTECTED]]
>Sent: Monday, September 16, 2002 11:36 AM
>To: John Almberg; [EMAIL PROTECTED]
>Subject: Re: dealing with Prime Numbers
>
>
>Explanation:
>This one-liner first rewrites the number as a sequence of ones.  For
>example, 5 = "11111", 6 = "111111", 9 = "111111111".
>That is accomplished by the 1x$_ (where $_ will be the number under 
>question
>from 2 to 1000).
>Then, it finds any number from 2 to 1000 (the shift) that does not match
>this pattern:
>^(11+?)\1+$
>The pattern checks for repetitions in the string.
>In other words, it checks for a certain number of 1s (must be at least 
>two),
>repeated over and over again to compose the entire number of 1s.  For
>example, 9 can be broken into three parts
>(111) (111) (111).  Since 9 can be broken into three parts, it is divisible
>by 3.
>5 cannot be broken into equally sized parts therefore it is not prime.
>
>HTH,
>Tanton
>----- Original Message -----
>From: "John Almberg" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Monday, September 16, 2002 11:30 AM
>Subject: RE: dealing with Prime Numbers
>
>
> > Okay, I'm impressed . . . I've been looking at this for a few minutes 
>and
> > have NO idea why this works. A little explanation, please?!?! :-)
> >
> > -- John
> >
> > > -----Original Message-----
> > > From: Paul Johnson [mailto:[EMAIL PROTECTED]]On Behalf Of Paul Johnson
> > > Sent: Monday, September 16, 2002 11:17 AM
> > > To: Angerstein
> > > Cc: [EMAIL PROTECTED]
> > > Subject: Re: dealing with Prime Numbers
> > >
> > >
> > > On Mon, Sep 16, 2002 at 03:10:41PM +0200, Angerstein wrote:
> > >
> > > > Does anyone here have an idea of how to get all prime numbers
> > > between 1 and
> > > > 1000?
> > >
> > > perl -e 'print"@{[grep{(1x$_)!~/^(11+?)\1+$/}2..shift||1e2]}\n"' 1000
> > >
> > > Next!
> > >
> > > --
> > > Paul Johnson - [EMAIL PROTECTED]
> > > http://www.pjcj.net
> > >
> > > --
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]




_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to