aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-063/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-063/jaldhar-h-vyas/perl/ch-1.pl27
-rwxr-xr-xchallenge-063/jaldhar-h-vyas/perl/ch-2.pl20
-rwxr-xr-xchallenge-063/jaldhar-h-vyas/raku/ch-1.p611
-rwxr-xr-xchallenge-063/jaldhar-h-vyas/raku/ch-2.p616
5 files changed, 75 insertions, 0 deletions
diff --git a/challenge-063/jaldhar-h-vyas/blog.txt b/challenge-063/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..715f7ff894
--- /dev/null
+++ b/challenge-063/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2020/06/perl_weekly_challenge_week_63.html
diff --git a/challenge-063/jaldhar-h-vyas/perl/ch-1.pl b/challenge-063/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..7f9108a180
--- /dev/null
+++ b/challenge-063/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+
+sub last_word {
+ my ($string, $regexp) = @_;
+ if (ref($regexp) ne 'Regexp') {
+ die "Not a regexp!";
+ }
+ my $result = undef;
+
+ for my $word (reverse split /\s+/, $string) {
+ if ($word =~ $regexp) {
+ $result = $word;
+ last;
+ }
+ }
+
+ return $result;
+}
+
+
+say last_word(' hello world', qr/[ea]l/) // 'undef'; # 'hello'
+say last_word("Don't match too much, Chet!", qr/ch.t/i) // 'undef'; # 'Chet!'
+say last_word("spaces in regexp won't match", qr/in re/) // 'undef'; # undef
+say last_word( join(' ', 1..1e6), qr/^(3.*?){3}/) // 'undef'; # '399933' \ No newline at end of file
diff --git a/challenge-063/jaldhar-h-vyas/perl/ch-2.pl b/challenge-063/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..ae7925c581
--- /dev/null
+++ b/challenge-063/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+
+sub rotations {
+ my ($original) = @_;
+ my $word = $original;
+ my $word_length = length $original;
+ my $rotation = 0;
+
+ do {
+ $rotation++;
+ $word .= substr $word, 0, $rotation % $word_length, q{};
+ } until ($word eq $original);
+
+ return $rotation;
+}
+
+say rotations('xyxxy'); \ No newline at end of file
diff --git a/challenge-063/jaldhar-h-vyas/raku/ch-1.p6 b/challenge-063/jaldhar-h-vyas/raku/ch-1.p6
new file mode 100755
index 0000000000..4af44f9afb
--- /dev/null
+++ b/challenge-063/jaldhar-h-vyas/raku/ch-1.p6
@@ -0,0 +1,11 @@
+#!/usr/bin/perl6
+
+sub last_word(Str $string, Regex $regexp) {
+ return $string.split(/\s+/).reverse.first($regexp) // Nil;
+}
+
+
+say last_word(' hello world', rx/<[ea]>l/) // 'undef'; # 'hello'
+say last_word("Don't match too much, Chet!", rx:i/ch.t/) // 'undef'; # 'Chet!'
+say last_word("spaces in regexp won't match", rx/in' 're/) // 'undef'; # undef
+say last_word((1 .. 1e6).join(' '), rx/^(3.*?) ** 3/) // 'undef'; # '399933' \ No newline at end of file
diff --git a/challenge-063/jaldhar-h-vyas/raku/ch-2.p6 b/challenge-063/jaldhar-h-vyas/raku/ch-2.p6
new file mode 100755
index 0000000000..cd61ee4c69
--- /dev/null
+++ b/challenge-063/jaldhar-h-vyas/raku/ch-2.p6
@@ -0,0 +1,16 @@
+#!/usr/bin/perl6
+
+sub rotations(Str $original) {
+ my $word = $original;
+ my $word_length = $original.chars;
+ my $rotation = 0;
+
+ repeat {
+ $rotation++;
+ $word ~~ s/ ^ ( . ** { $rotation % $word_length} ) (.+)/$1$0/;
+ } until ($word eq $original);
+
+ return $rotation;
+}
+
+say rotations('xyxx'); \ No newline at end of file