aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-05-04 22:33:08 +0100
committerGitHub <noreply@github.com>2024-05-04 22:33:08 +0100
commitc982eade86fdcfcae9b9cc7e5a2ff8711ec7b582 (patch)
treeb5f9ca9a3e9e0a8c447cb57c39ae17114f732e2d
parent06d30bd183b33ce35ab008d49e499b078685aa15 (diff)
parentda5882dbe73af83055ceb6aa71929af02023781e (diff)
downloadperlweeklychallenge-club-c982eade86fdcfcae9b9cc7e5a2ff8711ec7b582.tar.gz
perlweeklychallenge-club-c982eade86fdcfcae9b9cc7e5a2ff8711ec7b582.tar.bz2
perlweeklychallenge-club-c982eade86fdcfcae9b9cc7e5a2ff8711ec7b582.zip
Merge pull request #10038 from wambash/challenge-week-267
solutions week 267
-rw-r--r--challenge-267/wambash/raku/ch-1.raku19
-rw-r--r--challenge-267/wambash/raku/ch-2.raku30
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
+}