aboutsummaryrefslogtreecommitdiff
path: root/challenge-064
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-06-15 00:42:02 +0100
committerGitHub <noreply@github.com>2020-06-15 00:42:02 +0100
commit8f28b6ed59447a6d5629ff9fba277e9fc8fa2843 (patch)
treeeda149b311b990906fa1fcdd78bfd7c7928ce8d9 /challenge-064
parent4eb98f92f2ccf0ffb3637b7cb7b46f116c03b62a (diff)
parent178042244e39d6e16e93417b97135a9ec3ad1fc7 (diff)
downloadperlweeklychallenge-club-8f28b6ed59447a6d5629ff9fba277e9fc8fa2843.tar.gz
perlweeklychallenge-club-8f28b6ed59447a6d5629ff9fba277e9fc8fa2843.tar.bz2
perlweeklychallenge-club-8f28b6ed59447a6d5629ff9fba277e9fc8fa2843.zip
Merge pull request #1825 from jaldhar/challenge-064
Challenge 64 by Jaldhar H. Vyas
Diffstat (limited to 'challenge-064')
-rw-r--r--challenge-064/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-064/jaldhar-h-vyas/perl/ch-1.pl42
-rwxr-xr-xchallenge-064/jaldhar-h-vyas/perl/ch-2.pl16
-rwxr-xr-xchallenge-064/jaldhar-h-vyas/raku/ch-1.p638
-rwxr-xr-xchallenge-064/jaldhar-h-vyas/raku/ch-2.p614
5 files changed, 111 insertions, 0 deletions
diff --git a/challenge-064/jaldhar-h-vyas/blog.txt b/challenge-064/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..aca29fd85d
--- /dev/null
+++ b/challenge-064/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2020/06/perl_weekly_challenge_week_64.html
diff --git a/challenge-064/jaldhar-h-vyas/perl/ch-1.pl b/challenge-064/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..03daf932f2
--- /dev/null
+++ b/challenge-064/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+
+my $matrix = [
+ [1, 2, 3],
+ [4, 5, 6],
+ [7, 8, 9],
+];
+
+my $bottom_edge = scalar @{$matrix} - 1;
+my $right_edge = scalar @{$matrix->[0]} - 1; # assuming matrix is square
+my $row = 0;
+my $col = 0;
+my $total = $matrix->[0]->[0];
+my @path;
+push @path, $matrix->[0]->[0];
+
+while ($row < $bottom_edge || $col < $right_edge) {
+
+ my $down = 1_000_000;
+ if ($row + 1 <= $bottom_edge) {
+ $down = $total + $matrix->[$row + 1]->[$col];
+ }
+
+ my $right = 1_000_000;
+ if ($col + 1 <= $right_edge) {
+ $right = $total + $matrix->[$row]->[$col + 1];
+ }
+
+ if ($down < $right) {
+ $row++;
+ $total = $down;
+ } else {
+ $col++;
+ $total = $right;
+ }
+ push @path, $matrix->[$row]->[$col];
+}
+
+say join ' -> ', @path;
diff --git a/challenge-064/jaldhar-h-vyas/perl/ch-2.pl b/challenge-064/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..af28609e30
--- /dev/null
+++ b/challenge-064/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+
+sub search {
+ my ($S, @W) = @_;
+ my @results;
+
+ push @results, grep { $S =~ /$_/ } @W;
+
+ return (scalar @results) ? join ', ', @results : 0;
+}
+
+say search("perlweeklychallenge", ("weekly", "challenge", "perl"));
+say search("perlandraku", ("python", "ruby", "haskell"));
diff --git a/challenge-064/jaldhar-h-vyas/raku/ch-1.p6 b/challenge-064/jaldhar-h-vyas/raku/ch-1.p6
new file mode 100755
index 0000000000..14ae836e44
--- /dev/null
+++ b/challenge-064/jaldhar-h-vyas/raku/ch-1.p6
@@ -0,0 +1,38 @@
+#!/usr/bin/perl6
+my @matrix = [
+ [1, 2, 3],
+ [4, 5, 6],
+ [7, 8, 9],
+];
+
+my $bottom_edge = @matrix.elems - 1;
+my $right_edge = @matrix[0].elems - 1; # assuming matrix is square
+my $row = 0;
+my $col = 0;
+my $total = @matrix[0][0];
+my @path;
+@path.push(@matrix[0][0]);
+
+while $row != $bottom_edge || $col != $right_edge {
+
+ my $down = ∞;
+ if ($row + 1 <= $bottom_edge) {
+ $down = $total + @matrix[$row + 1][$col];
+ }
+
+ my $right = ∞;
+ if ($col + 1 <= $right_edge) {
+ $right = $total + @matrix[$row][$col + 1];
+ }
+
+ if ($down < $right) {
+ $row++;
+ $total = $down;
+ } else {
+ $col++;
+ $total = $right;
+ }
+ @path.push(@matrix[$row][$col]);
+}
+
+@path.join(' -> ').say;
diff --git a/challenge-064/jaldhar-h-vyas/raku/ch-2.p6 b/challenge-064/jaldhar-h-vyas/raku/ch-2.p6
new file mode 100755
index 0000000000..be4442420c
--- /dev/null
+++ b/challenge-064/jaldhar-h-vyas/raku/ch-2.p6
@@ -0,0 +1,14 @@
+#!/usr/bin/perl6
+sub search($S, @W) {
+ my @results;
+
+ for @W -> $word {
+ if $S ~~ /$word/ {
+ @results.push($word);
+ }
+ }
+ return @results.elems ?? @results.join(', ') !! 0;
+}
+
+say search("perlweeklychallenge", ["weekly", "challenge", "perl"]);
+say search("perlandraku", ("python", "ruby", "haskell"));