in reply to recursively generating permutations

Beauty is in the eye of the beholder, but I prefer this arrangement of the same algorithm:

#! perl -slw use strict; sub permutations { return !@_ ? [] : map{ my( $elem, $n ) = ( $_, 1 ); map{ [ $elem, @$_ ] } permutations( grep{ !/$elem/ or !$n-- } @_ ); } @_; } print @$_ for permutations @ARGV;

Or better, this one:

sub permutations { return !@_ ? [] : map{ my $next = $_; map{ [ $_[ $next ], @$_ ] } permutations( @_[ 0 .. $_-1, $_+1 .. $#_ ] ); } 0 .. $#_; } print @$_ for permutations @ARGV;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.