Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: is it prime?

by brx (Pilgrim)
on May 06, 2012 at 14:21 UTC ( #969141=note: print w/ replies, xml ) Need Help??


in reply to is it prime?

Where is my hammer?

sub isPrime($) { $n=pop; 1^(1x$n--)=~/^(1{2,$n})\1+$/; }

With n>2

Just for fun as a contrib to https://github.com/fxn/math-with-regexps/blob/master/one-liners.sh (fxn).

Update, thanks to ambrus's reply: Re^2: is it prime?

sub isPrime($) { (1x pop)!~/^(11+)\1+$/ }


Comment on Re: is it prime?
Select or Download Code
Replies are listed 'Best First'.
Re^2: is it prime?
by ambrus (Abbot) on May 06, 2012 at 17:32 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2015-07-31 11:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls