From 45850703fb9ee19c40a4f1966f31f49e6e98fa18 Mon Sep 17 00:00:00 2001 From: David Ferrone Date: Mon, 13 Oct 2025 11:00:04 -0400 Subject: Week 343 --- challenge-343/zapwai/perl/ch-1.pl | 21 ++++++++++++++++ challenge-343/zapwai/perl/ch-2.pl | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 challenge-343/zapwai/perl/ch-1.pl create mode 100644 challenge-343/zapwai/perl/ch-2.pl 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); -- cgit