diff options
| -rw-r--r-- | challenge-070/luca-ferrari/raku/ch-1.p6 | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-070/luca-ferrari/raku/ch-1.p6 b/challenge-070/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..f3d3c3adf0 --- /dev/null +++ b/challenge-070/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,18 @@ +#!raku + + +sub MAIN( Str $S, + Int $C where { $C >= 1 }, + Int $O where { $O >= 1 && $O >= $C && ( $C + $O ) <= $S.chars } ) { + my $N = $S.chars; + + say "$S with $N chars, swap counter $C and offset $O"; + + my @chars = $S.split( '', :skip-empty ); + for 1 .. $C { + my ( $index-left, $index-right ) = $_ % $N, ( $_ + $O ) % $N; + ( @chars[ $index-left ], @chars[ $index-right ] ) = @chars[ $index-right ], @chars[ $index-left ]; + } + + @chars.join.say; +} |
