From 4e652aa206e5f24e3dc8adec7d5c8c392261c227 Mon Sep 17 00:00:00 2001 From: Jan Krňávek Date: Sat, 31 May 2025 15:07:43 +0200 Subject: solutions week 323 --- challenge-323/wambash/raku/ch-1.raku | 26 ++++++++++++++++++++++++++ challenge-323/wambash/raku/ch-2.raku | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 challenge-323/wambash/raku/ch-1.raku create mode 100644 challenge-323/wambash/raku/ch-2.raku 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; +} -- cgit