Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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
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 +]

-Blake


Comment on Re: Re: Prime Number Finder
Download Code
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.
Re: Re: Re: Prime Number Finder
by NodeReaper (Curate) on Feb 20, 2002 at 18:41 UTC

    Reason: (elusion) dupe

    For more information on this node visit: this

Re: Re: Re: Prime Number Finder
by NodeReaper (Curate) on Feb 20, 2002 at 18:41 UTC

    Reason: (elusion) also a dupe (I guess that makes it a triplicate)

    For more information on this node visit: this

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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-12-26 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (164 votes), past polls