It's partly a faq. But that didn't do it for me without
modifications. A little molding:
use SuperSplit;
# tsc-permute: permute each word of input
@ret=([]);
sub permute {
my @items = @{ $_[0] };
my @perms = @{ $_[1] };
unless (@items) {
@perms=@perms[0..($#perms/2)];
push @ret, [@perms];
} else {
my(@newitems,@newperms,$i);
foreach $i (0 .. $#items)
{
@newitems = @items;
@newperms = @perms;
unshift(@newperms, splice(@newitems, $i, 1));
permute([@newitems], [@newperms]);
}
}
@ret;
}
print superjoin(' ',' | ',[permute([1..5],[1..5])]);
#result:
#| 5 4 3 2 1 | 4 5 3 2 1 | 5 3 4 2 1 | 3 5 4 2 1 | 4 3 5 2 1 | 3 4 5 2
+ 1 | 5 4 2 3 1 | 4 5 2 3 1 | 5 2 4 3 1 | 2 5 4 3 1 | 4 2 5 3 1 | 2 4
+5 3 1 | 5 3 2 4 1 | 3 5 2 4 1 | 5 2 3 4 1 | 2 5 3 4 1 | 3 2 5 4 1 | 2
+ 3 5 4 1 | 4 3 2 5 1 | 3 4 2 5 1 | 4 2 3 5 1 | 2 4 3 5 1 | 3 2 4 5 1
+| 2 3 4 5 1 | 5 4 3 1 2 | 4 5 3 1 2 | 5 3 4 1 2 | 3 5 4 1 2 | 4 3 5 1
+ 2 | 3 4 5 1 2 | 5 4 1 3 2 | 4 5 1 3 2 | 5 1 4 3 2 | 1
#..... und so weiter
Hope this helpsJeroen
"We
are not alone"(FZ) |