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

Re: check for power of a number with regex

by ikegami (Patriarch)
on Oct 26, 2009 at 01:25 UTC ( [id://803188]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        my $n = ...;
        my $b = ...;
    ...
            @possibles;
    
        print( "$n: ", ('1' x $n) =~ /^$pat\z/ ?1:0, "\n" );
    
  2. or download this
        my $n    = ...;
        my $b    = ...;
    ...
        my $pat = qr/(1|((?-2))\g{-1}{$b_m1})/;
    
        print( "$n: ", ('1' x $n) =~ /^$pat\z/ ?1:0, "\n" );
    
  3. or download this
        local our $pat;
        $pat = qr/
    ...
            \g{-1}{$b_m1}
            (?(?{ $^N =~ $pat })(?=)|(?!))
        /x;
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-24 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found