Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Working with Binary Numbers

by jdporter (Paladin)
on Sep 24, 2007 at 20:52 UTC ( [id://640819]=note: print w/replies, xml ) Need Help??


in reply to Working with Binary Numbers

This is rather brute-force (exponential in the length of the pattern), but at least it's (somewhat) succinct.

sub expand_binary_patterns { map { my $l = length($_); my $q = $_; $q =~ y/-/./; grep { sprintf('%0'.$l.'b',$_) =~ /$q/ } 0 .. (2**$l)-1; } @_ } my @data = qw( 000- 0101 011- 1-0- ); @data = expand_binary_patterns( @data );

Update: blokhead++ :-)

Log In?
Username:
Password:

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

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

    No recent polls found