From 72ad6970d5138f2b64df947362652c81024a2ca8 Mon Sep 17 00:00:00 2001 From: Util Date: Sat, 25 Nov 2023 19:19:47 -0500 Subject: Add TWC 244 solutions by Bruce Gray (In Raku only). --- challenge-244/bruce-gray/raku/ch-1.raku | 15 +++++++++++++++ challenge-244/bruce-gray/raku/ch-2.raku | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 challenge-244/bruce-gray/raku/ch-1.raku create mode 100644 challenge-244/bruce-gray/raku/ch-2.raku 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; +} -- cgit