OR if you MUST have it in that order you could reverse the order of your array lists, or with my solution use this solution:my ($carry, @tallykeeper) = map 0, @arrays, 0; #gets rid of warnings.. +. w/strictures while (!$carry) { $carry = 1; for my $dx (0 .. $#arrays ) { print $arrays[$dx]->[$tallykeeper[$dx]]; $tallykeeper[$dx] += $carry; if ($tallykeeper[$dx] < @{$arrays[$dx]}) { $carry = 0; }else{ $tallykeeper[$dx] = 0; } } print "\n"; }
my ($carry, @tallykeeper) = map 0, @arrays, 0; #gets rid of warnings.. +. while (!$carry) { $carry = 1; my $combostr = ""; for my $dx (reverse 0 .. $#arrays ) { $combostr .= $arrays[$dx]->[$tallykeeper[$dx]]; $tallykeeper[$dx] += $carry; if ($tallykeeper[$dx] < @{$arrays[$dx]}) { $carry = 0; }else{ $tallykeeper[$dx] = 0; } } $combostr = reverse $combostr; print "$combostr\n"; }
Okay mine are ultra lame... but it was fun to try to make a generic solution that worked for everything possible array of arrays...
--Ray
In reply to Re: Generating all possible combinations from an AoA
by raybies
in thread Generating all possible combinations from an AoA
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |