aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaldhar H. Vyas <jaldhar@braincells.com>2025-06-01 23:53:50 -0400
committerJaldhar H. Vyas <jaldhar@braincells.com>2025-06-01 23:53:50 -0400
commit7f6dad803c03aee03010892819032307f726128e (patch)
tree3d9cc8f517ece0b28009498b2c4bd90f654e815a
parent9731fa92325c312010151736871bbb31522235e4 (diff)
downloadperlweeklychallenge-club-7f6dad803c03aee03010892819032307f726128e.tar.gz
perlweeklychallenge-club-7f6dad803c03aee03010892819032307f726128e.tar.bz2
perlweeklychallenge-club-7f6dad803c03aee03010892819032307f726128e.zip
Challenge 323 by Jaldhar H. Vyas.
-rw-r--r--challenge-323/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-323/jaldhar-h-vyas/perl/ch-1.pl16
-rwxr-xr-xchallenge-323/jaldhar-h-vyas/perl/ch-2.pl19
-rwxr-xr-xchallenge-323/jaldhar-h-vyas/raku/ch-1.raku18
-rwxr-xr-xchallenge-323/jaldhar-h-vyas/raku/ch-2.raku22
5 files changed, 76 insertions, 0 deletions
diff --git a/challenge-323/jaldhar-h-vyas/blog.txt b/challenge-323/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..cd2d1a13b5
--- /dev/null
+++ b/challenge-323/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2025/06/perl_weekly_challenge_week_323.html
diff --git a/challenge-323/jaldhar-h-vyas/perl/ch-1.pl b/challenge-323/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..e0fd4b82eb
--- /dev/null
+++ b/challenge-323/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+use v5.38;
+
+my @operations = @ARGV;
+my $total = 0;
+
+for my $operation (@operations) {
+ if ($operation =~ /\+\+/) {
+ $total++;
+ }
+ if ($operation =~ /\-\-/) {
+ $total--;
+ }
+}
+
+say $total;
diff --git a/challenge-323/jaldhar-h-vyas/perl/ch-2.pl b/challenge-323/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..b304c2a002
--- /dev/null
+++ b/challenge-323/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+use v5.38;
+
+my ($income, @tax) = @ARGV;
+my $taxed = 0;
+my %taxes = map { my ($k, $v) = split /\s+/, $_; $k => $v } @tax;
+my $total = 0;
+
+for my $bracket ( sort { $a <=> $b } keys %taxes ) {
+ if ($taxed >= $income) {
+ last;
+ }
+
+ my $tax = ($bracket > $income ? $income : $bracket) - $taxed;
+ $taxed += $tax;
+ $total += $tax * ($taxes{$bracket} / 100);
+}
+
+say $total;
diff --git a/challenge-323/jaldhar-h-vyas/raku/ch-1.raku b/challenge-323/jaldhar-h-vyas/raku/ch-1.raku
new file mode 100755
index 0000000000..1009734930
--- /dev/null
+++ b/challenge-323/jaldhar-h-vyas/raku/ch-1.raku
@@ -0,0 +1,18 @@
+#!/usr/bin/raku
+
+sub MAIN(
+ *@operations
+) {
+ my $total = 0;
+
+ for @operations -> $operation {
+ if $operation ~~ /\+\+/ {
+ $total++;
+ }
+ if $operation ~~ /\-\-/ {
+ $total--;
+ }
+ }
+
+ say $total;
+} \ No newline at end of file
diff --git a/challenge-323/jaldhar-h-vyas/raku/ch-2.raku b/challenge-323/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..2effb7f3c3
--- /dev/null
+++ b/challenge-323/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,22 @@
+#!/usr/bin/raku
+
+sub MAIN(
+ Int $income,
+ *@tax
+) {
+ my $taxed = 0;
+ my %taxes = @tax.map({ [=>] $_.words });
+ my $total = 0;
+
+ for %taxes.keys.sort({$^a <=> $^b }) -> $bracket {
+ if $taxed >= $income {
+ last;
+ }
+
+ my $tax = ($bracket > $income ?? $income !! $bracket) - $taxed;
+ $taxed += $tax;
+ $total += $tax * (%taxes{$bracket} / 100);
+ }
+
+ say $total;
+} \ No newline at end of file