Here's another "recursive" solution. :-)
sub perms { die "Bad args\n" unless @_; my $p = @_; my $i = 2; $p /= $i++ until $p % $i; return @_ if $i > @{ $_[ 0 ] }; push @_, [ @{ $_[ -1 ] } ]; @{ $_[ -1 ] }[ 0..$i-1 ] = reverse @{ $_[ -1 ] }[ 0..$i-1 ]; goto &perms; }
the lowliest monk
In reply to Re: recursively generating permutations
by tlm
in thread recursively generating permutations
by spurperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |