aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoelle Maslak <jmaslak@antelope.net>2023-07-12 18:10:22 -0400
committerJoelle Maslak <jmaslak@antelope.net>2023-07-12 18:10:22 -0400
commit832fcb22fb7e5af716cd931f51722810cd7b07c6 (patch)
tree0017cd14bc3a8a73645ed7245ca28d60521cc942
parent650b20acfed91315dc9d4ebfc16ad9f0ca8df0d3 (diff)
downloadperlweeklychallenge-club-832fcb22fb7e5af716cd931f51722810cd7b07c6.tar.gz
perlweeklychallenge-club-832fcb22fb7e5af716cd931f51722810cd7b07c6.tar.bz2
perlweeklychallenge-club-832fcb22fb7e5af716cd931f51722810cd7b07c6.zip
Solution in Raku for Challenge 225
-rwxr-xr-xchallenge-225/joelle-maslak/raku/ch-1.raku14
-rwxr-xr-xchallenge-225/joelle-maslak/raku/ch-2.raku25
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-225/joelle-maslak/raku/ch-1.raku b/challenge-225/joelle-maslak/raku/ch-1.raku
new file mode 100755
index 0000000000..547d9fd6ba
--- /dev/null
+++ b/challenge-225/joelle-maslak/raku/ch-1.raku
@@ -0,0 +1,14 @@
+#!/usr/bin/env raku
+use v6.d;
+
+my Str:D @INPUT = ("Perl and Raku belong to the same family.",
+ "I love Perl.",
+ "The Perl and Raku Conference.");
+
+sub MAIN(*@input) {
+ @input = @INPUT unless @input.elems;
+
+ say "Max words: " ~ max @input».words».elems.max;
+}
+
+
diff --git a/challenge-225/joelle-maslak/raku/ch-2.raku b/challenge-225/joelle-maslak/raku/ch-2.raku
new file mode 100755
index 0000000000..3c5f6fd4aa
--- /dev/null
+++ b/challenge-225/joelle-maslak/raku/ch-2.raku
@@ -0,0 +1,25 @@
+#!/usr/bin/env raku
+use v6.d;
+
+my @INPUT = (10, 4, 8, 3);
+
+sub leftsum(@numbers) {
+ return () unless @numbers.elems;
+ gather {
+ for 0..^(@numbers.elems) -> $i {
+ take @numbers[0..^$i].sum;
+ }
+ }
+}
+
+sub MAIN(*@input) {
+ @input = @INPUT unless @input.elems;
+
+ my @left = leftsum(@input);
+ my @right = leftsum(@input.reverse).reverse;
+
+ my @differences = (@left Z @right).map: {abs($^a[0] - $^a[1])};
+ say "Left/right sum differences: " ~ @differences.join(", ");
+}
+
+