Talk:Permutations by swapping: Difference between revisions

Content added Content deleted
(→‎Python code issues: Maybe it is not like your current impression.)
Line 50: 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)
: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>