aboutsummaryrefslogtreecommitdiff
path: root/challenge-063/arne-sommer/raku/rostr
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-06-03 23:51:28 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-06-03 23:51:28 +0100
commit0b33db6d7ec47fbde3d3a91c202e633d5715a608 (patch)
treefcb04afa0285f05eea125268dbbeaf4b5fbf888b /challenge-063/arne-sommer/raku/rostr
parent2449f9a8821f7ed54f532107cfb11dbb43e138af (diff)
downloadperlweeklychallenge-club-0b33db6d7ec47fbde3d3a91c202e633d5715a608.tar.gz
perlweeklychallenge-club-0b33db6d7ec47fbde3d3a91c202e633d5715a608.tar.bz2
perlweeklychallenge-club-0b33db6d7ec47fbde3d3a91c202e633d5715a608.zip
- Added solutions by Arne Sommer.
Diffstat (limited to 'challenge-063/arne-sommer/raku/rostr')
-rwxr-xr-xchallenge-063/arne-sommer/raku/rostr36
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";
+}