- or download this
## Filtering tye's "combinations" (power set) iterator:
my $iter = combinations(@S);
...
next unless @c == $K;
...
}
- or download this
## Using tye's Algorithm::Loops:
NestedLoops(
...
( sub { [$_+1 .. $#S] } ) x ($K - 1),
sub { my @c = @S[@_]; ... }
}
- or download this
sub combinations {
my ($num, $arr) = @_;
...
return @$arr[@pick];
};
}
- or download this
my $iter = combinations( 3 => ['a' .. 'f'] );
while ( my @c = $iter->() ) {
print "@c\n";
}