Anonymous user
Permutations: Difference between revisions
→{{header|Perl 6}}: use built-in
(Liberty BASIC added) |
(→{{header|Perl 6}}: use built-in) |
||
Line 2,269:
=={{header|Perl 6}}==
{{works with|rakudo|
First, you can just use the built-in method on any list type.
<lang Perl6>
{{out}}
<pre>a b c
Line 2,287 ⟶ 2,280:
c b a</pre>
Here is
<lang perl6>sub next_perm ( @a is copy ) {
my $j = @a.end - 1;
Line 2,312 ⟶ 2,305:
c b a
</pre>
Here is
<lang perl6>sub permute(@items) {
my @seq := 1..+@items;
gather for (^[*] @seq) -> $n is copy {
Line 2,326 ⟶ 2,318:
}
}
.say for permute( 'a'..'c' )</lang>
{{out}}
<pre>a b c
Line 2,336 ⟶ 2,327:
c b a
</pre>
Finally, if you just want zero-based numbers, you can call the built-in function:
<lang perl6>.say for permutations(3);</lang>
{{out}}
<pre>0 1 2
0 2 1
1 0 2
1 2 0
2 0 1
2 1 0</pre>
=={{header|PicoLisp}}==
|