aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-10-14 09:30:24 +0100
committerGitHub <noreply@github.com>2025-10-14 09:30:24 +0100
commitaf30f4cf7c01021c3897e7e7ba7b64d244ec17c2 (patch)
tree4ceaa678b5a0658673167d067ae451b7b3936ed4
parent0858044be5977f805ad25980a704695021f2c1c5 (diff)
parent45850703fb9ee19c40a4f1966f31f49e6e98fa18 (diff)
downloadperlweeklychallenge-club-af30f4cf7c01021c3897e7e7ba7b64d244ec17c2.tar.gz
perlweeklychallenge-club-af30f4cf7c01021c3897e7e7ba7b64d244ec17c2.tar.bz2
perlweeklychallenge-club-af30f4cf7c01021c3897e7e7ba7b64d244ec17c2.zip
Merge pull request #12841 from zapwai/branch-for-343
Week 343
-rw-r--r--challenge-343/zapwai/perl/ch-1.pl21
-rw-r--r--challenge-343/zapwai/perl/ch-2.pl51
2 files changed, 72 insertions, 0 deletions
diff --git a/challenge-343/zapwai/perl/ch-1.pl b/challenge-343/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..febcfbb999
--- /dev/null
+++ b/challenge-343/zapwai/perl/ch-1.pl
@@ -0,0 +1,21 @@
+use v5.38;
+
+sub proc(@n) {
+ say "Input: (@n)";
+ my $min = abs($n[0]);
+ for my $val (@n) {
+ $min = abs($val) if (abs($val) < $min);
+ }
+ say "Output: $min";
+}
+
+my @nums = (4,2,-1,3-2);
+proc(@nums);
+@nums = (-5, 5, -3, 3, -1, 1);
+proc(@nums);
+@nums = (7, -3, 0, 2, -8);
+proc(@nums);
+@nums = (-2, -5, -1, -8);
+proc(@nums);
+@nums = (-2, 2, -4, 4, -1, 1);
+proc(@nums);
diff --git a/challenge-343/zapwai/perl/ch-2.pl b/challenge-343/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..cb669583b3
--- /dev/null
+++ b/challenge-343/zapwai/perl/ch-2.pl
@@ -0,0 +1,51 @@
+use v5.38;
+use List::Util "sum";
+
+sub proc(@g) {
+ say "Input: ";
+ my $row_max = 0;
+ my $row = 0;
+ my $o = 0;
+ for my $r (@g) {
+ my $s = sum(@$r);
+ if ($s > $row_max) {
+ $row_max = $s;
+ $o = $row;
+ }
+ $row++;
+ }
+ say "Output: Team $o (with $row_max wins)";
+}
+
+my @grid = (
+ [0, 1, 1],
+ [0, 0, 1],
+ [0, 0, 0],
+);
+proc(@grid);
+@grid = (
+ [0, 1, 0, 0],
+ [0, 0, 0, 0],
+ [1, 1, 0, 0],
+ [1, 1, 1, 0],
+);
+proc(@grid);
+@grid = (
+ [0, 1],
+ [0, 0],
+);
+proc(@grid);
+@grid = (
+ [0, 1, 1],
+ [0, 0, 0],
+ [0, 1, 0],
+);
+proc(@grid);
+@grid = (
+ [0, 0, 0, 0, 0],
+ [1, 0, 0, 0, 0],
+ [1, 1, 0, 1, 1],
+ [1, 1, 0, 0, 0],
+ [1, 1, 0, 1, 0],
+);
+proc(@grid);