Post History
Perl, 103 bytes Takes two lines of space-delimited numbers on stdin. First is the list, second is the indices. Prints shuffled result to stdout. perl -E'@a=<>=~/\d+/g;$i=@i=<>=~/\d+...
#3: Post edited
- # Perl, 103 bytes
- Takes two lines of space-delimited numbers on stdin.
- First is the list, second is the indices.
- Prints shuffled result to stdout.
- ```
perl -E'@a=<>=~/\d+/g;$i=@i=<>=~/\d+/g;while($i>0){$j=int rand$i--;@a[@i[$i,$j]]=@a[@i[$j,$i]]}say"@a"'- ```
- ```
- perl -E'
- @a = <>=~/\d+/g;
- $i = @i = <>=~/\d+/g;
- # Fisher-Yates/Durstenfeld shuffle
while ($i>0) {- $j = int rand $i--;
- @a[ @i[$i,$j] ] = @a[ @i[$j,$i] ] # directly update @a
- }
- say "@a"
- '
- ```
[Try it online!][TIO-mn1o6rok][TIO-mn1o6rok]: https://tio.run/##TczNCoJAFIbhvVfxIQcsUtTKSmxk7sNmMeBYZxAJf4iIuvVpFi1avs/ivZuxL9wyGXRGz8toEE36GVVOanGuxSe9tJv0WhELyf/wuHFvVsR1tn6RFTzMGPXQEidJJXUjuSGOySolfmVjYqXefh5KHTqXIccWO@xR4IAjTiiRZwE8wzM8wzNQBl8 "Perl 5 – Try It Online"
- # Perl, 103 bytes
- Takes two lines of space-delimited numbers on stdin.
- First is the list, second is the indices.
- Prints shuffled result to stdout.
- ```
- perl -E'@a=<>=~/\d+/g;$i=@i=<>=~/\d+/g;while($i>1){$j=int rand$i--;@a[@i[$i,$j]]=@a[@i[$j,$i]]}say"@a"'
- ```
- ```
- perl -E'
- @a = <>=~/\d+/g;
- $i = @i = <>=~/\d+/g;
- # Fisher-Yates/Durstenfeld shuffle
- while ($i>1) {
- $j = int rand $i--;
- @a[ @i[$i,$j] ] = @a[ @i[$j,$i] ] # directly update @a
- }
- say "@a"
- '
- ```
- [Try it online!][TIO-mn1ofhvc]
- [TIO-mn1ofhvc]: https://tio.run/##TczNCoJAFIbhvVfxIQcsUtTKSmxk7sNmMeBYZxAJf4iIuvVpFi1avs/ivZuxL9wyGXRGz8toEE36GVVOanGuxSe9tJv0WhELyf/wuHFvVsR1vn6RFTzMGPXQEidJJXUjuSGOySolfmVjYqXefh5KHTqXIccWO@xR4IAjTiiRZwE8wzM8wzNQBl8 "Perl 5 – Try It Online"
#2: Post edited
# Perl, 101 bytes- Takes two lines of space-delimited numbers on stdin.
- First is the list, second is the indices.
- Prints shuffled result to stdout.
- ```
perl -E'@a=<>=~/\d+/g;$i=@i=<>=~/\d+/g;while($i--){$j=int rand$i;@a[@i[$i,$j]]=@a[@i[$j,$i]]}say"@a"'- ```
- ```
- perl -E'
- @a = <>=~/\d+/g;
- $i = @i = <>=~/\d+/g;
- # Fisher-Yates/Durstenfeld shuffle
while ($i--) {$j = int rand $i;- @a[ @i[$i,$j] ] = @a[ @i[$j,$i] ] # directly update @a
- }
- say "@a"
- '
- ```
[Try it online!][TIO-mn1nufqb][TIO-mn1nufqb]: https://tio.run/##TcxLCsIwFEbheVfxUy5UsaWtWrXESPZRMwg06g2lSB@IiG49ZuDA4fkG526HrvLzaHGxZpoHi2Q0z0R4ZeTxJD/5uV3lV0EsFf/D48adXRBn2fJFTnI/YTB9SyyUaRQ3xCk5reWvXEqs9TusY2Vi7wuUWGODLSrssMcBNcoiQmAERmAEBuroCw "Perl 5 – Try It Online"
- # Perl, 103 bytes
- Takes two lines of space-delimited numbers on stdin.
- First is the list, second is the indices.
- Prints shuffled result to stdout.
- ```
- perl -E'@a=<>=~/\d+/g;$i=@i=<>=~/\d+/g;while($i>0){$j=int rand$i--;@a[@i[$i,$j]]=@a[@i[$j,$i]]}say"@a"'
- ```
- ```
- perl -E'
- @a = <>=~/\d+/g;
- $i = @i = <>=~/\d+/g;
- # Fisher-Yates/Durstenfeld shuffle
- while ($i>0) {
- $j = int rand $i--;
- @a[ @i[$i,$j] ] = @a[ @i[$j,$i] ] # directly update @a
- }
- say "@a"
- '
- ```
- [Try it online!][TIO-mn1o6rok]
- [TIO-mn1o6rok]: https://tio.run/##TczNCoJAFIbhvVfxIQcsUtTKSmxk7sNmMeBYZxAJf4iIuvVpFi1avs/ivZuxL9wyGXRGz8toEE36GVVOanGuxSe9tJv0WhELyf/wuHFvVsR1tn6RFTzMGPXQEidJJXUjuSGOySolfmVjYqXefh5KHTqXIccWO@xR4IAjTiiRZwE8wzM8wzNQBl8 "Perl 5 – Try It Online"
#1: Initial revision
# Perl, 101 bytes
Takes two lines of space-delimited numbers on stdin.
First is the list, second is the indices.
Prints shuffled result to stdout.
```
perl -E'@a=<>=~/\d+/g;$i=@i=<>=~/\d+/g;while($i--){$j=int rand$i;@a[@i[$i,$j]]=@a[@i[$j,$i]]}say"@a"'
```
```
perl -E'
@a = <>=~/\d+/g;
$i = @i = <>=~/\d+/g;
# Fisher-Yates/Durstenfeld shuffle
while ($i--) {
$j = int rand $i;
@a[ @i[$i,$j] ] = @a[ @i[$j,$i] ] # directly update @a
}
say "@a"
'
```
[Try it online!][TIO-mn1nufqb]
[TIO-mn1nufqb]: https://tio.run/##TcxLCsIwFEbheVfxUy5UsaWtWrXESPZRMwg06g2lSB@IiG49ZuDA4fkG526HrvLzaHGxZpoHi2Q0z0R4ZeTxJD/5uV3lV0EsFf/D48adXRBn2fJFTnI/YTB9SyyUaRQ3xCk5reWvXEqs9TusY2Vi7wuUWGODLSrssMcBNcoiQmAERmAEBuroCw "Perl 5 – Try It Online"
