diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-05-31 23:21:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-31 23:21:45 +0100 |
| commit | 6253622700c1d82448793550b43ffed1bba1e1df (patch) | |
| tree | 253e1287b7f8f14cf170453b1c983e701674eeca | |
| parent | 8721292c1ea533fae4a15e69724ae686a845f1ce (diff) | |
| parent | 4e652aa206e5f24e3dc8adec7d5c8c392261c227 (diff) | |
| download | perlweeklychallenge-club-6253622700c1d82448793550b43ffed1bba1e1df.tar.gz perlweeklychallenge-club-6253622700c1d82448793550b43ffed1bba1e1df.tar.bz2 perlweeklychallenge-club-6253622700c1d82448793550b43ffed1bba1e1df.zip | |
Merge pull request #12108 from wambash/challenge-week-323
solutions week 323
| -rw-r--r-- | challenge-323/wambash/raku/ch-1.raku | 26 | ||||
| -rw-r--r-- | challenge-323/wambash/raku/ch-2.raku | 26 |
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; +} |
