aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Krňávek <Jan.Krnavek@gmail.com>2025-05-31 15:07:43 +0200
committerJan Krňávek <Jan.Krnavek@gmail.com>2025-05-31 15:07:43 +0200
commit4e652aa206e5f24e3dc8adec7d5c8c392261c227 (patch)
treec45d9ca5a6a752f5063459b73ab90e2cf404036e
parent4e6933931646d1faaec0b80ee00e6e7d12fedaa7 (diff)
downloadperlweeklychallenge-club-4e652aa206e5f24e3dc8adec7d5c8c392261c227.tar.gz
perlweeklychallenge-club-4e652aa206e5f24e3dc8adec7d5c8c392261c227.tar.bz2
perlweeklychallenge-club-4e652aa206e5f24e3dc8adec7d5c8c392261c227.zip
solutions week 323
-rw-r--r--challenge-323/wambash/raku/ch-1.raku26
-rw-r--r--challenge-323/wambash/raku/ch-2.raku26
2 files changed, 52 insertions, 0 deletions
diff --git a/challenge-323/wambash/raku/ch-1.raku b/challenge-323/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..bda0944f0a
--- /dev/null
+++ b/challenge-323/wambash/raku/ch-1.raku
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+
+enum Operation (
+ 'x++' => 1,
+ '++x' => 1,
+ 'x--' => -1,
+ '--x' => -1,
+);
+
+sub increment-decrement (+operations) {
+ operations
+ andthen .map: { Operation::{$_} }\
+ andthen .sum
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is increment-decrement(< --x x++ x++ >), 1;
+ is increment-decrement(< x++ ++x x++ >), 3;
+ is increment-decrement(< x++ ++x x-- --x >), 0;
+ done-testing;
+}
+
+multi MAIN (+operations) {
+ say increment-decrement operations;
+}
diff --git a/challenge-323/wambash/raku/ch-2.raku b/challenge-323/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..50bfb5426f
--- /dev/null
+++ b/challenge-323/wambash/raku/ch-2.raku
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+
+sub tax-amount-redu (($income, $acc=0), ($upto, $tax)) {
+ my $tax-base = $income min $upto;
+ ($income - $tax-base, $acc + $tax-base*$tax/100 )
+}
+
+sub tax-amount (+tax,:$income) {
+ my @tax-diff = tax.produce: -> ($aupto, $atax), ($upto,$tax) { ($upto-$aupto, $tax) };
+
+ ($income,0), |@tax-diff
+ andthen .reduce: &tax-amount-redu
+ andthen .tail
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is tax-amount((3,50),(7,10),(12,25)):10income, 2.65;
+ is tax-amount((1,0),(4,25),(5,50)):2income, 0.25;
+ is tax-amount(((2,50),)):0income, 0;
+ done-testing;
+}
+
+multi MAIN (+tax, :$income) {
+ say tax-amount tax.batch(2), :$income;
+}