http://qs1969.pair.com?node_id=631006

thenetfreaker has asked for the wisdom of the Perl Monks concerning the following question:

Hello dear monks, I'm trying to create a function that by getting a number of Ones and Zeroes (if possible also the number of the generation) shall give eventually give all the conbinations without repeats, because Algorithm::Combinatorics can't differ 2 zeroes( for it 010 and 010 is different, but for me it's the same).

I've come with an idea of printing them chronologically like (if $ones=2 and $zeroes=3):
00011
00101
01001
10001
00110
01010
10010
01100
10100
11000
where these 10 are all variations without repeats.

i tried achieving my goal in 2 ways :
1. trying to simply print then like that -
sub combinationN { my ($O,$Z,$current) = @_; my $string = ''; my $toMove = 0; my @states; my $now = $current - ($current-$Z); $states[0] = $current; while ($current > $Z) { $current -= $now+1; $states[$toMove] = $current % ($Z+1); $toMove++; } for (1..$Z-$states[0]) {$string .= '0'} for (1..$O-$toMove) {$string .= '1'} # foreach (@states) { for (1..$states[0]) {$string .= '0'} for (1..$toMove) {$string .= '1'} # } print "$string\n"; return $string }
but this gave out
00011
00110
01100
11000
00101
01001
10001
and afterwars there were strange thigs like 000110000, etc; also it didn't print 00110,01010,...,01100,etc.

2. printing them by distanses from zero to one using a flipFlop flag (after a set of ones there must com a set of zeroes and the opposite) -
sub combinationN { my ($O,$Z,$current,$tL) = @_; my $string = ''; my $ff = 1; my $Dc = 0; my $Oc = int($current % $O); ## my $Zc = int($current % $Z); ## my $place = 1; while ($tL > $place) { if ($ff eq 1) { $Dc = $O-$Oc; for (1..$Dc) {$string .= '1'} $Oc = $Dc; } else { $Dc = $Z-$Zc; for (1..$Dc) {$string .= '0'} $Zc = $Dc; } $place += $Dc; $ff *= -1; } print "$string\n"; return $string }
but this gave out
11000
1001
11000
1000
1100
10100
11000
1001
and many other strange reasults.

I searched Google and Google-Code-search and the only similar things i found were connected to colors and cropping the results that repeated (but still all the results( 24! ) were checked).

Is there a simple logical way to print it out( using map() or/and join()) or fixing one of the codes i tried ?