good chemistry is complicated,and a little bit messy -LW PerlMonks

### Re: Re: Prime Number Finder

by blakem (Monsignor)
 on Feb 20, 2002 at 18:30 UTC ( #146608=note: print w/replies, xml ) Need Help??

in reply to Re: Prime Number Finder

"but I just thought of a better way to calculate primes"
Did you actually "just think that up" cause it looks quite a bit like one that abigail wrote:
perl -wle 'print "Prime" if (1 x shift) !~ /^1?\$|^(11+?)\1+\$/' [number +]

-Blake

Replies are listed 'Best First'.
Re^3: Prime Number Finder
by Anonymous Monk on Mar 07, 2005 at 14:41 UTC
How does this work?
The regular expression match tries to break the string "111.." (a string of 1's as long as your input number) into some number of equal-length pieces of length two or more. It uses non-greedy matching, so it starts with the smallest possible and works up.. "11","111","1111" and so on. This is the same order of efficiency as the OP's prime test loop (one at a time), but it uses the regular expression engine.
Re: Re: Re: Prime Number Finder
by The_Rev (Acolyte) on Feb 20, 2002 at 18:40 UTC
my apologies to Blake, no I didn't 'just think that up', it actually is abigails code with a slight modication.

Create A New User
Node Status?
node history
Node Type: note [id://146608]
help
Chatterbox?
 [Lady_Aleena]: Corion, I knew that, I was just giving Discipulus a hard time. choroba likes the story at the end of the node [choroba]: reminds me of the days at the bank [Corion]: Lady_Aleena: Hehe ;-D [Lady_Aleena]: Corion, it was PerlMonks who kept pushing me to get Linux, so now I know some of the commands to use in word play. [Corion]: Lady_Aleena: :-D

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2017-04-26 08:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
I'm a fool:

Results (471 votes). Check out past polls.