Sattolo cycle: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
m (→‎{{header|Perl 6}}: Add demo of usage)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 419:
Shuffled e = 13 18 14 20 17 15 21 19 16 12 22 11
</pre>
 
=={{header|C sharp|C#}}==
<lang csharp>private static readonly Random Rand = new Random();
 
void sattoloCycle<T>(IList<T> items) {
for (var i = items.Count; i-- > 1;) {
int j = Rand.Next(i);
var tmp = items[i];
items[i] = items[j];
items[j] = tmp;
}
}</lang>
 
=={{header|C++}}==
Line 487 ⟶ 499:
cycled: 13 17 14 22 11 18 20 12 21 19 15 16
</pre>
 
=={{header|C sharp|C#}}==
<lang csharp>private static readonly Random Rand = new Random();
 
void sattoloCycle<T>(IList<T> items) {
for (var i = items.Count; i-- > 1;) {
int j = Rand.Next(i);
var tmp = items[i];
items[i] = items[j];
items[j] = tmp;
}
}</lang>
 
=={{header|D}}==
Line 1,068:
<pre> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
18 5 9 25 3 23 12 2 26 21 16 4 11 15 20 1 27 10 29 7 6 28 24 8 13 17 19 0 14 30 22</pre>
=={{header|Perl 6}}==
 
This modifies the array passed as argument, in-place.
 
<lang perl6>sub sattolo-cycle (@array) {
for reverse 1 .. @array.end -> $i {
my $j = (^$i).pick;
@array[$j, $i] = @array[$i, $j];
}
 
my @a = flat 'A' .. 'Z', 'a' .. 'z';
 
say @a;
sattolo-cycle(@a);
say @a;</lang>
 
{{out|Sample output}}
<pre>[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z]
[r G w g W Z D X M f Q A c i H Y J F s z m v x P b U j n q I N e O L o C d u a K S V l y R T B k t h p E]</pre>
 
=={{header|Phix}}==
Line 1,207 ⟶ 1,187:
{{out}}
<pre>'#(21 19 12 11 18 17 14 16 15 13 20)</pre>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
 
This modifies the array passed as argument, in-place.
 
<lang perl6>sub sattolo-cycle (@array) {
for reverse 1 .. @array.end -> $i {
my $j = (^$i).pick;
@array[$j, $i] = @array[$i, $j];
}
 
my @a = flat 'A' .. 'Z', 'a' .. 'z';
 
say @a;
sattolo-cycle(@a);
say @a;</lang>
 
{{out|Sample output}}
<pre>[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z]
[r G w g W Z D X M f Q A c i H Y J F s z m v x P b U j n q I N e O L o C d u a K S V l y R T B k t h p E]</pre>
 
=={{header|REXX}}==
Line 1,282 ⟶ 1,284:
{{out}}
<pre> pre 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
post 3 4 8 18 14 21 20 13 10 1 25 7 2 24 12 23 5 11 6 22 16 19 9 0 15 17</pre>
 
=={{header|Ring}}==
Line 1,383 ⟶ 1,385:
a
}</lang>
 
=={{header|SequenceL}}==
<lang sequenceL>
10,333

edits