Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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
in thread 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 +]


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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://146608]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2019-10-14 04:14 GMT
Find Nodes?
    Voting Booth?