aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-08-25 21:02:11 +0100
committerGitHub <noreply@github.com>2025-08-25 21:02:11 +0100
commit418e12e5697cddd3ee8ad1996c20e600298d7737 (patch)
tree89ff15fd2b8cfc6ef4313f5b2f7dfa3ccb4fe2b0
parentc13fb4e8ab09d579048a1dcfe211b127ce792213 (diff)
parent0dc07844839304810a131b5311e0b9e3913478b2 (diff)
downloadperlweeklychallenge-club-418e12e5697cddd3ee8ad1996c20e600298d7737.tar.gz
perlweeklychallenge-club-418e12e5697cddd3ee8ad1996c20e600298d7737.tar.bz2
perlweeklychallenge-club-418e12e5697cddd3ee8ad1996c20e600298d7737.zip
Merge pull request #12571 from zapwai/branch-for-336
Week 336
-rw-r--r--challenge-336/zapwai/perl/ch-1.pl26
-rw-r--r--challenge-336/zapwai/perl/ch-2.pl36
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-336/zapwai/perl/ch-1.pl b/challenge-336/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..2416dbbb36
--- /dev/null
+++ b/challenge-336/zapwai/perl/ch-1.pl
@@ -0,0 +1,26 @@
+use v5.38;
+
+sub proc(@ints) {
+ say "Input: @ints";
+ my %f;
+ $f{$_}++ for (@ints);
+ my $o;
+ for my $k (keys %f) {
+ if ($f{$k} == 1) {
+ $o = "false";
+ }
+ }
+ $o = "true" unless ($o);
+ say "Output: $o"
+}
+
+my @ints = (1,1,2,2,2,2);
+proc(@ints);
+@ints = (1,1,1,2,2,2,3,3);
+proc(@ints);
+@ints = (5,5,5,5,5,5,7,7,7,7,7,7);
+proc(@ints);
+@ints = (1,2,3,4);
+proc(@ints);
+@ints = (8,8,9,9,10,10,11,11);
+proc(@ints);
diff --git a/challenge-336/zapwai/perl/ch-2.pl b/challenge-336/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..7557f4913e
--- /dev/null
+++ b/challenge-336/zapwai/perl/ch-2.pl
@@ -0,0 +1,36 @@
+use v5.38;
+use List::Util qw(sum);
+
+sub proc(@scores) {
+ say "Input: @scores";
+ my @s;
+ my $si = 0;
+ for my $i (0 .. $#scores) {
+ if ($scores[$i] eq "C") {
+ pop @s;
+ $si--;
+ } elsif ($scores[$i] eq "D") {
+ push @s, 2*$s[$si-1];
+ $si++;
+ } elsif ($scores[$i] eq "+") {
+ my $val = $s[$si-1] + $s[$si-2];
+ push @s, $val;
+ $si++;
+ } else {
+ push @s, $scores[$i];
+ $si++;
+ }
+ }
+ say "Output: " . sum(@s);
+}
+
+my @scores = ("5","2","C","D","+");
+proc(@scores);
+@scores = ("5","-2","4","C","D","9","+","+");
+proc(@scores);
+@scores = ("7","D","D","C","+","3");
+proc(@scores);
+@scores = ("-5","-10","+","D","C","+");
+proc(@scores);
+@scores = ("3","6","+","D","C","8","+","D","-2","C","+");
+proc(@scores);