diff options
| -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; +} |
