aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUtil <bruce.gray@acm.org>2023-11-25 19:19:47 -0500
committerUtil <bruce.gray@acm.org>2023-11-25 19:19:47 -0500
commit72ad6970d5138f2b64df947362652c81024a2ca8 (patch)
tree57dd6dc7a7b5d722f8f74c50ead18ef15ff40698
parentc42b89630cf7082c105df06276d9de6ea6ccd4d7 (diff)
downloadperlweeklychallenge-club-72ad6970d5138f2b64df947362652c81024a2ca8.tar.gz
perlweeklychallenge-club-72ad6970d5138f2b64df947362652c81024a2ca8.tar.bz2
perlweeklychallenge-club-72ad6970d5138f2b64df947362652c81024a2ca8.zip
Add TWC 244 solutions by Bruce Gray (In Raku only).
-rw-r--r--challenge-244/bruce-gray/raku/ch-1.raku15
-rw-r--r--challenge-244/bruce-gray/raku/ch-2.raku15
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-244/bruce-gray/raku/ch-1.raku b/challenge-244/bruce-gray/raku/ch-1.raku
new file mode 100644
index 0000000000..f8893b7c34
--- /dev/null
+++ b/challenge-244/bruce-gray/raku/ch-1.raku
@@ -0,0 +1,15 @@
+sub task1 ( @ns ) {
+ return @ns.map: (@ns X< *).sum;
+}
+
+
+constant @tests =
+ ( (8, 1, 2, 2, 3) , (4, 0, 1, 1, 3) ),
+ ( (6, 5, 4, 8) , (2, 1, 0, 3) ),
+ ( (2, 2, 2) , (0, 0, 0) ),
+;
+
+use Test; plan +@tests;
+for @tests -> (@in, @expected) {
+ is-deeply task1(@in), @expected;
+}
diff --git a/challenge-244/bruce-gray/raku/ch-2.raku b/challenge-244/bruce-gray/raku/ch-2.raku
new file mode 100644
index 0000000000..c133d601e8
--- /dev/null
+++ b/challenge-244/bruce-gray/raku/ch-2.raku
@@ -0,0 +1,15 @@
+sub task2 ( @strengths ) {
+
+ sub power (@seq) { [*] @seq.minmax.bounds.[0,1,1] }
+
+ return sum map &power, combinations(@strengths, 1..*);
+}
+
+
+constant @tests =
+ ( 141, (2, 1, 4) ),
+;
+use Test; plan +@tests;
+for @tests -> ($expected, @in) {
+ is task2(@in), $expected;
+}