sub combinations { my @array = @_; if ($#array == 0) {return [ $array[0] ]; } my @results; my $element; foreach $element (0..$#array) { my @leftovers = @array; my $chosen_one = splice(@leftovers, $element, 1); foreach (&combinations(@leftovers)) { push(@results, [ $chosen_one, @{$_} ]); } } return @results; } use Data::Dumper; print Dumper(&combinations(qw(a b c d)));
In reply to Permutations by octothorpe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |