diff options
| -rw-r--r-- | challenge-267/wambash/raku/ch-1.raku | 19 | ||||
| -rw-r--r-- | challenge-267/wambash/raku/ch-2.raku | 30 |
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-267/wambash/raku/ch-1.raku b/challenge-267/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..135de94d56 --- /dev/null +++ b/challenge-267/wambash/raku/ch-1.raku @@ -0,0 +1,19 @@ +#!/usr/bin/env raku + +sub product-sign (+ints) { + ints + andthen .map: *.sign + andthen [*] $_ +} + +multi MAIN (Bool :test($)!) { + use Test; + is product-sign(-1, -2, -3, -4, 3, 2, 1), 1; + is product-sign(1, 2, 0, -2, -1), 0; + is product-sign(-1, -1, 1, -1, 2), -1; + done-testing; +} + +multi MAIN (+ints) { + say product-sign ints +} diff --git a/challenge-267/wambash/raku/ch-2.raku b/challenge-267/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..d9a09c3f0c --- /dev/null +++ b/challenge-267/wambash/raku/ch-2.raku @@ -0,0 +1,30 @@ +#!/usr/bin/env raku + +sub join-sum ((:$str, :$sum, :$line), Pair $y) { + ($sum + $y.value ≤ 100) + ?? \(str => $str ~ $y.key, sum => $sum + $y.value, :$line ) + !! \(str => $y.key, sum => $y.value, line =>$line+1) +} + +sub line-counts ($str, +widths) { + my %letters = 'a'..'z' Z=> widths; + + $str.comb + andthen .map: { $_ => %letters{$_} }\ + andthen \(:str(''),:0sum,:1line), |$_ + andthen .reduce: &join-sum + andthen .<line sum> +} + +multi MAIN (Bool :test($)!) { + use Test; + is-deeply join-sum((:str('ab'),:20sum, :3line), 'c' => 5), \(:str('abc'), :25sum, :3line); + is-deeply join-sum((:str('abc'),:95sum, :3line), 'd' => 10), \(:str('d'), :10sum, :4line); + is-deeply line-counts(([~] 'a'..'z'), 10 xx 26), (3,60); + is-deeply line-counts('bbbcccdddaaa', 4,slip 10 xx 26), (2,4); + done-testing; +} + +multi MAIN ($str, +widths) { + put line-counts $str, widths +} |
