'00111',
'01011',
'01101',
'01110',
'10011',
'10101',
'10110',
'11001',
'11010',
'11100'
So it looks like you're shifting the highest bit up by
one, then the next highest bit, then the next, until you've
run out of empty bits. How about something like (untested):
use Bit::Vector;
my $joins = 2;
my $splits = 3;
my $length = $joins+$splits;
my $start = '0'x$joins . '1'x$splits;
my $vector = Bit::Vector->new_Bin($length, $start);
my @combinations = ();
for my $pos ($joins-1..$length-1) { # 0-based, right?
for my $bit ($splits-1..0) {
$vector->bit_flip($pos+$bit);
$vector->bit_flip($pos+$bit-1);
push @combinations, $vector->to_Bin();
}
}
--
The hell with paco, vote for Erudil!
:wq
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.