aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-06-01 17:19:56 +0100
committerGitHub <noreply@github.com>2020-06-01 17:19:56 +0100
commit2e536e7d60bb069b9621554d4a713764e8ef77d1 (patch)
treebbb34060d55d542a74176ef86db64c191498ddf3
parent9c731cd86595f4599b00c1c0c4ecfe556e8ef286 (diff)
parent1cf60888493d988d87466a46aa702097ebe48f07 (diff)
downloadperlweeklychallenge-club-2e536e7d60bb069b9621554d4a713764e8ef77d1.tar.gz
perlweeklychallenge-club-2e536e7d60bb069b9621554d4a713764e8ef77d1.tar.bz2
perlweeklychallenge-club-2e536e7d60bb069b9621554d4a713764e8ef77d1.zip
Merge pull request #1780 from Scimon/master
Challenge 1 :)
-rw-r--r--challenge-063/simon-proctor/raku/ch-1.raku13
-rw-r--r--challenge-063/simon-proctor/raku/ch-2.raku21
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-063/simon-proctor/raku/ch-1.raku b/challenge-063/simon-proctor/raku/ch-1.raku
new file mode 100644
index 0000000000..ed1092c70c
--- /dev/null
+++ b/challenge-063/simon-proctor/raku/ch-1.raku
@@ -0,0 +1,13 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub last_word( Str $sentence, Regex $test ) {
+ $sentence.words.reverse.first( $test );
+}
+
+# Test Last_word
+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/"in re"/); # undef
+say last_word( join(' ', 1..1e6), rx/^(3.*?) ** 3/); # '399933'
diff --git a/challenge-063/simon-proctor/raku/ch-2.raku b/challenge-063/simon-proctor/raku/ch-2.raku
new file mode 100644
index 0000000000..2696b581f6
--- /dev/null
+++ b/challenge-063/simon-proctor/raku/ch-2.raku
@@ -0,0 +1,21 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+#| Given a string home many rotations are needed (see the challenge for the rules on rotations).
+sub MAIN ( Str $input where m!^<[xy]>+$! ) {
+ my Int $i = 1;
+ my Str $rotated = rotate_string( $input, $i );
+
+ while ( $rotated !~~ $input ) {
+ $i++;
+ $rotated = rotate_string( $rotated, $i );
+ }
+
+ say $i;
+}
+
+sub rotate_string( Str $rotated, Int $i ) {
+ my $midpoint = $i % $rotated.codes;
+ "{$rotated.substr($midpoint,$rotated.codes-$midpoint)}{$rotated.substr(0,$midpoint)}";
+}