Permutations by swapping: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
m (→‎{{header|C}}: Remove vanity tags)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 903:
Perm: [2, 1, 3, 4] Sign: -1
</pre>
 
=={{header|F_Sharp|F#}}==
See [http://www.rosettacode.org/wiki/Zebra_puzzle#F.23] for an example using this module
Line 957 ⟶ 958:
<null>
</pre>
 
=={{header|Forth}}==
{{libheader|Forth Scientific Library}}
Line 2,078 ⟶ 2,080:
{{out}}
The output is the same as the first perl solution.
 
=={{header|Perl 6}}==
 
=== Recursive ===
{{works with|rakudo|2015-09-25}}
<lang perl6>sub insert($x, @xs) { ([flat @xs[0 ..^ $_], $x, @xs[$_ .. *]] for 0 .. +@xs) }
sub order($sg, @xs) { $sg > 0 ?? @xs !! @xs.reverse }
multi perms([]) {
[] => +1
multi perms([$x, *@xs]) {
perms(@xs).map({ |order($_.value, insert($x, $_.key)) }) Z=> |(+1,-1) xx *
.say for perms([0..2]);</lang>
 
{{out}}
<pre>[0 1 2] => 1
[1 0 2] => -1
[1 2 0] => 1
[2 1 0] => -1
[2 0 1] => 1
[0 2 1] => -1</pre>
 
=={{header|Phix}}==
Line 2,519 ⟶ 2,496:
1, 0, 2, 3 (-1)
</pre>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
 
=== Recursive ===
{{works with|rakudo|2015-09-25}}
<lang perl6>sub insert($x, @xs) { ([flat @xs[0 ..^ $_], $x, @xs[$_ .. *]] for 0 .. +@xs) }
sub order($sg, @xs) { $sg > 0 ?? @xs !! @xs.reverse }
multi perms([]) {
[] => +1
multi perms([$x, *@xs]) {
perms(@xs).map({ |order($_.value, insert($x, $_.key)) }) Z=> |(+1,-1) xx *
.say for perms([0..2]);</lang>
 
{{out}}
<pre>[0 1 2] => 1
[1 0 2] => -1
[1 2 0] => 1
[2 1 0] => -1
[2 0 1] => 1
[0 2 1] => -1</pre>
 
=={{header|REXX}}==
Line 2,700 ⟶ 2,703:
}</lang>
{{Out}}See it in running in your browser by [https://scastie.scala-lang.org/DdM4xnUnQ2aNGP481zwcrw Scastie (JVM)].
 
=={{header|Sidef}}==
{{trans|Perl}}
10,333

edits