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 } #### 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 }