aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2025-05-26 10:17:05 -0400
committerGitHub <noreply@github.com>2025-05-26 10:17:05 -0400
commit21a57ae690b29631fc33df466eedc84968d85a03 (patch)
tree298aedcc1961d3d9acd25608572fe01134d15d89
parent0729d1308bfe2e7d4fc1ea6f41b40356645d4f72 (diff)
downloadperlweeklychallenge-club-21a57ae690b29631fc33df466eedc84968d85a03.tar.gz
perlweeklychallenge-club-21a57ae690b29631fc33df466eedc84968d85a03.tar.bz2
perlweeklychallenge-club-21a57ae690b29631fc33df466eedc84968d85a03.zip
Week 323
-rw-r--r--challenge-323/zapwai/perl/ch-1.pl20
-rw-r--r--challenge-323/zapwai/perl/ch-2.pl29
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-323/zapwai/perl/ch-1.pl b/challenge-323/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..2c1c7fe9a6
--- /dev/null
+++ b/challenge-323/zapwai/perl/ch-1.pl
@@ -0,0 +1,20 @@
+use feature qw( say signatures );
+sub proc(@operations) {
+ say "Input: \@operations = @operations";
+ my $x = 0;
+ foreach (@operations) {
+ if (/\+/) {
+ $x++;
+ } else {
+ $x--;
+ }
+ }
+ say "Output: $x"
+}
+
+my @operations = ("--x", "x++", "x++");
+proc(@operations);
+@operations = ("x++", "++x", "x++");
+proc(@operations);
+@operations = ("x++", "++x", "--x", "x--");
+proc(@operations);
diff --git a/challenge-323/zapwai/perl/ch-2.pl b/challenge-323/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..96fdc101b5
--- /dev/null
+++ b/challenge-323/zapwai/perl/ch-2.pl
@@ -0,0 +1,29 @@
+use feature qw( say signatures );
+
+sub proc($income, @tax) {
+ print "Input: \$income = $income, \n\t\@tax = ";
+ print "( ";
+ print '[' . join(", ", @$_) . '] ' for (@tax);
+ say ")";
+
+ my $tax = 0;
+ my $prev = 0;
+ for (@tax) {
+ my ($cap, $perc) = @$_;
+ if ($income >= $cap) {
+ $tax += ($cap - $prev)*$perc/100.0;
+ $prev = $cap;
+ } else {
+ $tax += ($income - $prev)*$perc/100.0;
+ last;
+ }
+ }
+ say "Output: $tax";
+}
+
+my $income = 10; my @tax = ([3, 50], [7, 10], [12,25]);
+proc($income, @tax);
+$income = 2; @tax = ([1, 0], [4, 25], [5,50]);
+proc($income, @tax);
+$income = 0; @tax = ([2, 50]);
+proc($income, @tax);