aboutsummaryrefslogtreecommitdiff
path: root/challenge-063/arne-sommer/raku
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
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')
-rwxr-xr-xchallenge-063/arne-sommer/raku/ch-1.p621
-rwxr-xr-xchallenge-063/arne-sommer/raku/ch-2.p636
-rwxr-xr-xchallenge-063/arne-sommer/raku/lawo21
-rwxr-xr-xchallenge-063/arne-sommer/raku/rostr36
4 files changed, 114 insertions, 0 deletions
diff --git a/challenge-063/arne-sommer/raku/ch-1.p6 b/challenge-063/arne-sommer/raku/ch-1.p6
new file mode 100755
index 0000000000..064388d9ef
--- /dev/null
+++ b/challenge-063/arne-sommer/raku/ch-1.p6
@@ -0,0 +1,21 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (:$verbose);
+
+sub last_word ($string, Regex $regex)
+{
+ say ": String: $string" if $verbose;
+
+ for $string.split(/\s/).reverse -> $word
+ {
+ say ": Word: $word (regex: { $regex.gist })" if $verbose;
+
+ return $word if $word ~~ $regex;
+ }
+ return;
+}
+
+say last_word(' hello world', rx/<[ea]>l/); # 'hello'
+say last_word("Don't match too much, Chet!", rx:i/ch.t/); # 'Chet!'
+say last_word("spaces in regexp won't match", rx:s/in re/); # undef
+say last_word( join(' ', 1..1e6), rx/^(3.*?) ** 3 /); # '399933'
diff --git a/challenge-063/arne-sommer/raku/ch-2.p6 b/challenge-063/arne-sommer/raku/ch-2.p6
new file mode 100755
index 0000000000..1e81450e5e
--- /dev/null
+++ b/challenge-063/arne-sommer/raku/ch-2.p6
@@ -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";
+}
diff --git a/challenge-063/arne-sommer/raku/lawo b/challenge-063/arne-sommer/raku/lawo
new file mode 100755
index 0000000000..064388d9ef
--- /dev/null
+++ b/challenge-063/arne-sommer/raku/lawo
@@ -0,0 +1,21 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (:$verbose);
+
+sub last_word ($string, Regex $regex)
+{
+ say ": String: $string" if $verbose;
+
+ for $string.split(/\s/).reverse -> $word
+ {
+ say ": Word: $word (regex: { $regex.gist })" if $verbose;
+
+ return $word if $word ~~ $regex;
+ }
+ return;
+}
+
+say last_word(' hello world', rx/<[ea]>l/); # 'hello'
+say last_word("Don't match too much, Chet!", rx:i/ch.t/); # 'Chet!'
+say last_word("spaces in regexp won't match", rx:s/in re/); # undef
+say last_word( join(' ', 1..1e6), rx/^(3.*?) ** 3 /); # '399933'
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";
+}