[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [Fun With Perl] A prime example



How about adding one character to make it 20% faster?

sub f{(1x shift)!~/^(11+?)\1+$/}

-b


Eric Raible wrote:
> 
> The trailing + is necessary.
> 
> Unless of course you want all odd numbers to be considered prime.
> 
> - Eric
> 
> ----------
> From:   Steve Willer
> Sent:   Thursday, June 10, 1999 4:02 PM
> To:     Eric Raible
> Cc:     fwp@technofile.org
> Subject:        Re: [Fun With Perl] A prime example
> 
> On Thu, 10 Jun 1999, Eric Raible wrote:
> 
> > Can anyone do this in fewer characters?
> >
> > sub f{(1x shift)!~/^(11+)\1+$/}
> 
>   sub f{(1x$_[0])!~/^(11+)\1$/}
> 
> I don't know what that last '+' was doing in your regexp.
> 
> ==== Want to unsubscribe from this list? (Don't you love us anymore?)
> ==== Well, if you insist... Send mail with body "unsubscribe" to
> ==== fwp-request@technofile.org

==== Want to unsubscribe from this list? (Don't you love us anymore?)
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org