diff options
Diffstat (limited to 'challenge-063/arne-sommer/raku/rostr')
| -rwxr-xr-x | challenge-063/arne-sommer/raku/rostr | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-063/arne-sommer/raku/rostr b/challenge-063/arne-sommer/raku/rostr new file mode 100755 index 0000000000..1e81450e5e --- /dev/null +++ b/challenge-063/arne-sommer/raku/rostr @@ -0,0 +1,36 @@ +#! /usr/bin/env raku + +subset XY where /^<[xy]>+$/; + +sub MAIN (XY $string = 'xyxx', :$verbose) +{ + my $length = $string.chars; + my $current = $string; + + my $count = 0; + + loop + { + $count++; + + my $rotate = $count % $length; + + if $rotate + { + my $a = $current.substr($rotate); + my $b = $current.substr(0, $rotate); + + $current = $a ~ $b; + + say ": Rotation $count: $current (moved '$b' to the end)" if $verbose; + } + elsif $verbose + { + say ": Rotation $count: $current (moved nothing)"; + } + + last if $current eq $string; + } + + say "$count Rotations"; +} |
