use strict;
use warnings;
use Algorithm::Loops qw( NestedLoops );
my @arr = qw( A B C D E F );
my $N = 2;
my $i = NestedLoops([
[ 0 .. @arr ],
( sub { [ $_ .. @arr ] } ) x ($N-1)
]);
while (my (@positions) = $i->()) {
my @tmp = @arr;
splice(@tmp, $_, 0, 'N') for reverse @positions;
print(join(',', @tmp), "\n");
}
####
while (my (@positions) = $i->()) {
my @tmp;
my $cur = 0;
for my $pos (@positions) {
push @tmp, @arr[$cur..$pos-1];
$cur = $pos;
push @tmp, 'N';
}
push @tmp, @arr[$cur..$#arr];
print(join(',', @tmp), "\n");
}
####
while (my (@positions) = $i->()) {
my $sep = '';
my $cur = 0;
for my $pos (@positions) {
print($sep);
$sep = ', ';
print($arr[$cur++], $sep) while $cur < $pos;
print('N');
}
print($sep, $arr[$cur++]) while $cur < @arr;
print("\n");
}