Jump to content

Talk:Permutations by swapping: Difference between revisions

Line 57:
<lang perl6>multi postfix:<!±>(@a where 1) { [@a] => +1 }
multi postfix:<!±>(@a) {
gathermy {$sign = 1;
take [ @a[0], .key.list ] => .valuegather for @a[1..*]!±; -> $a {
for$sign @a[1..*]= -> $a {1;
take [ $a, .key.list ] => -$sign * .value for @a.grep(none $a)!±
}
}
}
say .perl for <a b c>!±</lang>
</lang>
 
I think it's easier to understand but it doesn't return the permutations in the correct order:
Line 75 ⟶ 73:
["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:2641, 4 November 2012 (UTC)
1,934

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.