in reply to Re: •Re: Puzzle: need a more general algorithm

in thread Puzzle: need a more general algorithm

'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(); } }

In Section
Seekers of Perl Wisdom