aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Shitov <andy@shitov.ru>2025-06-02 07:42:52 +0200
committerAndrew Shitov <andy@shitov.ru>2025-06-02 07:42:52 +0200
commitcaf55f037fcd5c40ce78ace900bc493aa8b3c82c (patch)
treeaf0d1e91359c8669d57f5e8e4c78f5132a2c0572
parent0729d1308bfe2e7d4fc1ea6f41b40356645d4f72 (diff)
downloadperlweeklychallenge-club-caf55f037fcd5c40ce78ace900bc493aa8b3c82c.tar.gz
perlweeklychallenge-club-caf55f037fcd5c40ce78ace900bc493aa8b3c82c.tar.bz2
perlweeklychallenge-club-caf55f037fcd5c40ce78ace900bc493aa8b3c82c.zip
Week 324 solutions in Raku by @ash
-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;
+}