diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-06-03 13:03:40 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-03 13:03:40 +0100 |
| commit | e959cfd9e91d0d3cd960a8e5e0d28143f5b65aa8 (patch) | |
| tree | 1fc54481aff006df5c51f2384d04b74560b26b9d | |
| parent | b0159e77cc4e56da3a5a1c86d5769c652bcc887e (diff) | |
| parent | caf55f037fcd5c40ce78ace900bc493aa8b3c82c (diff) | |
| download | perlweeklychallenge-club-e959cfd9e91d0d3cd960a8e5e0d28143f5b65aa8.tar.gz perlweeklychallenge-club-e959cfd9e91d0d3cd960a8e5e0d28143f5b65aa8.tar.bz2 perlweeklychallenge-club-e959cfd9e91d0d3cd960a8e5e0d28143f5b65aa8.zip | |
Merge pull request #12114 from ash/ash-324
Week 324 solutions in Raku by @ash
| -rw-r--r-- | challenge-324/ash/raku/ch-1.raku | 21 | ||||
| -rw-r--r-- | challenge-324/ash/raku/ch-2.raku | 19 |
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; +} |
