aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-06-10 09:22:19 +0100
committerGitHub <noreply@github.com>2025-06-10 09:22:19 +0100
commite2acf0d6a834bb5e14b6540e0f7ffe60f64c2c67 (patch)
treea73899c96559ffda87f029be4a0efde60e7d929c
parent51e216c600c724a382d748fd00e10a0c264de5fd (diff)
parent8ba08be3f06767a9e224b8b8bb8f15a634fcf377 (diff)
downloadperlweeklychallenge-club-e2acf0d6a834bb5e14b6540e0f7ffe60f64c2c67.tar.gz
perlweeklychallenge-club-e2acf0d6a834bb5e14b6540e0f7ffe60f64c2c67.tar.bz2
perlweeklychallenge-club-e2acf0d6a834bb5e14b6540e0f7ffe60f64c2c67.zip
Merge pull request #12156 from zapwai/branch-for-325
Week 325
-rw-r--r--challenge-325/zapwai/ch-1.pl28
-rw-r--r--challenge-325/zapwai/ch-2.pl21
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-325/zapwai/ch-1.pl b/challenge-325/zapwai/ch-1.pl
new file mode 100644
index 0000000000..0d725ac4d8
--- /dev/null
+++ b/challenge-325/zapwai/ch-1.pl
@@ -0,0 +1,28 @@
+use v5.38;
+sub proc(@binary) {
+ say "Input: @binary";
+ my $max = 0;
+ my $run = 0;
+ my $flag = 0;
+ for my $i (0 .. $#binary) {
+ if ($binary[$i] == 1) {
+ if ($flag == 0) {
+ $run = 1;
+ $flag = 1;
+ } else {
+ $run++;
+ }
+ } else {
+ $flag = 0;
+ }
+ $max = $run if ($max < $run);
+ }
+ say "Output: $max";
+}
+
+my @binary = (0, 1, 1, 0, 1, 1, 1);
+proc(@binary);
+@binary = (0,0,0,0);
+proc(@binary);
+@binary = (1,0,1,0,1,1);
+proc(@binary);
diff --git a/challenge-325/zapwai/ch-2.pl b/challenge-325/zapwai/ch-2.pl
new file mode 100644
index 0000000000..ffb4f6db30
--- /dev/null
+++ b/challenge-325/zapwai/ch-2.pl
@@ -0,0 +1,21 @@
+use v5.38;
+sub proc(@prices) {
+ say "Input: @prices";
+ for my $i (0 .. $#prices) {
+ my $price = $prices[$i];
+ for my $j ($i + 1 .. $#prices) {
+ if ($prices[$j] <= $price) {
+ $prices[$i] -= $prices[$j];
+ last;
+ }
+ }
+ }
+ say "Output: @prices";
+}
+
+my @prices = (8, 4, 6, 2, 3);
+proc(@prices);
+@prices = (1,2,3,4,5);
+proc(@prices);
+@prices = (7,1,1,5);
+proc(@prices);