aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-324/ash/raku/ch-1.raku21
-rw-r--r--challenge-324/ash/raku/ch-2.raku19
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-324/ash/raku/ch-1.raku b/challenge-324/ash/raku/ch-1.raku
new file mode 100644
index 0000000000..f69d27e4a4
--- /dev/null
+++ b/challenge-324/ash/raku/ch-1.raku
@@ -0,0 +1,21 @@
+# Task 1 of Week 324
+# The Weekly Challenge
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-324/#TASK1
+
+# Note: the $r input from the task description is redundant
+# and is not used in the solution.
+
+# Test run:
+# $ raku ch-1.raku
+# ((1 2) (3 4))
+# ((1 2 3))
+# ((1) (2) (3) (4))
+
+say solve([1, 2, 3, 4], 2);
+say solve([1, 2, 3], 3);
+say solve([1, 2, 3, 4], 1);
+
+
+sub solve(@data, $width) {
+ return @data.rotor($width);
+}
diff --git a/challenge-324/ash/raku/ch-2.raku b/challenge-324/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..95044d929a
--- /dev/null
+++ b/challenge-324/ash/raku/ch-2.raku
@@ -0,0 +1,19 @@
+# Task 2 of Week 324
+# The Weekly Challenge
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-324/#TASK2
+
+say total-xor(1, 3); # 6
+say total-xor(5, 1, 6); # 28
+say total-xor(3, 4, 5, 6, 7, 8); # 480
+
+sub total-xor(*@data) {
+ my $sum = 0;
+
+ for 1..@data.elems {
+ for @data.combinations($_) -> @row {
+ $sum += [+^] @row;
+ }
+ }
+
+ return $sum;
+}