in reply to recursively generating permutations
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
|
|---|