Talk:Permutations by swapping: Difference between revisions

→‎Alternative Perl6 version: I remove this: it does not work properly
(→‎Alternative Perl6 version: I remove this: it does not work properly)
 
Line 50:
 
:Yep Ledrug, although its use in the other task is mentioned, somone made a well-meaning change to the functions interfacethat broke things. I have removed that change as it was quickest, but I should probably update the Matrix task in the future. --[[User:Paddy3118|Paddy3118]] 21:45, 4 August 2012 (UTC)
 
== Alternative Perl6 version ==
 
I have the following Perl6 alternative:
 
<lang perl6>multi postfix:<!±>(@a where 1) { [@a] => +1 }
multi postfix:<!±>(@a) {
my $sign = 1;
gather for @a -> $a {
$sign *= -1;
take [ $a, .key.list ] => $sign * .value for @a.grep(none $a)!±
}
}
say .perl for <a b c>!±</lang>
 
I think it's easier to understand but it doesn't return the permutations in the correct order:
{{out}}
<pre>
["a", "b", "c"] => 1
["a", "c", "b"] => -1
["b", "a", "c"] => -1
["b", "c", "a"] => 1
["c", "a", "b"] => 1
["c", "b", "a"] => -1
</pre>
--[[User:Grondilu|Grondilu]] 07:41, 4 November 2012 (UTC)
1,934

edits