perlmeditation
MeowChow
Another deceptively easy challenge: compose a golfed sub that takes an arbitrary list, and returns a list of all arrays that are permutations of that list. My best attempt is currently 72 chars:
<p>
<table bgcolor=green>
<tr><td><font color=green>
<code>sub p {@_?do{my$x=pop;map{my@l=@$_;map[@l[0..$_-1],$x,@l[$_..$#l]],0..@l}&p}:[]}</code></font>
</tr></td>
</table>
<code>
p(1, 2, 3) should return:
(
[3, 2, 1],
[2, 3, 1],
[2, 1, 3],
[3, 1, 2],
[1, 3, 2],
[1, 2, 3]
)
</code>
<b>Extra Credit</b>: Produce a non-recursive solution.
<pre>
<a href="/index.pl?node=MeowChow"> MeowChow </a>
s aamecha.s a..a\u$&owag.print</pre>