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)
 
(One intermediate revision by the same user not shown)
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) {
gather {
take [ @a[0], .key.list ] => .value for @a[1..*]!±;
for @a[1..*] -> $a {
take [ $a, .key.list ] => -.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>
Edit: hum, it's actually the value of the signature that is wrong. Nevermind.--[[User:Grondilu|Grondilu]] 07:26, 4 November 2012 (UTC)
1,934

edits