aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-225/bruce-gray/raku/ch-1.raku17
-rw-r--r--challenge-225/bruce-gray/raku/ch-2.raku22
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-225/bruce-gray/raku/ch-1.raku b/challenge-225/bruce-gray/raku/ch-1.raku
new file mode 100644
index 0000000000..d0f9b529cb
--- /dev/null
+++ b/challenge-225/bruce-gray/raku/ch-1.raku
@@ -0,0 +1,17 @@
+sub task1 (@sentences --> UInt) {
+ return @sentences.map( *.words.elems ).max;
+}
+
+# Shorter:
+# my &task1 = *».words».elems.max;
+
+
+my @tests =
+ ( 8, ( 'Perl and Raku belong to the same family.', 'I love Perl.', 'The Perl and Raku Conference.', ) ),
+ ( 7, ( 'The Weekly Challenge.', 'Python is the most popular guest language.', 'Team PWC has over 300 members.' ) ),
+;
+use Test;
+plan +@tests;
+for @tests -> ( $expected, @sentences ) {
+ is task1(@sentences), $expected;
+}
diff --git a/challenge-225/bruce-gray/raku/ch-2.raku b/challenge-225/bruce-gray/raku/ch-2.raku
new file mode 100644
index 0000000000..c017f23950
--- /dev/null
+++ b/challenge-225/bruce-gray/raku/ch-2.raku
@@ -0,0 +1,22 @@
+sub abs_diff { abs $^x - $^y }
+sub partial_sum_0 { 0, |[\+] @^a.head(*-1) }
+
+sub task2 ( Int @ns --> Array ) {
+
+ my @left = partial_sum_0(@ns);
+ my @right = partial_sum_0(@ns.reverse).reverse;
+
+ return @left »[&abs_diff]« @right;
+}
+
+
+my @tests =
+ ( (10, 4, 8, 3) , (15, 1, 11, 22) ),
+ ( (1,) , (0,) ),
+ ( (1, 2, 3, 4, 5) , (14, 11, 6, 1, 10) ),
+;
+use Test;
+plan +@tests;
+for @tests -> ( @in, @expected ) {
+ is-deeply task2( Array[Int].new(@in) ), @expected.Array;
+}