aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Shitov <ash@Andreys-iMac.local>2024-05-08 08:22:47 +0300
committerAndrey Shitov <ash@Andreys-iMac.local>2024-05-08 08:22:47 +0300
commitc663a66dc485208600a12b8c43cd54ef66239831 (patch)
treec1709aa2a5b96b38080822d405d7e10410236ada
parentcaa8f919e75d8a57fd87f44df4f30b20ea629946 (diff)
downloadperlweeklychallenge-club-c663a66dc485208600a12b8c43cd54ef66239831.tar.gz
perlweeklychallenge-club-c663a66dc485208600a12b8c43cd54ef66239831.tar.bz2
perlweeklychallenge-club-c663a66dc485208600a12b8c43cd54ef66239831.zip
Task 2
-rw-r--r--challenge-268/ash/raku/ch-1.raku3
-rw-r--r--challenge-268/ash/raku/ch-2.raku27
2 files changed, 28 insertions, 2 deletions
diff --git a/challenge-268/ash/raku/ch-1.raku b/challenge-268/ash/raku/ch-1.raku
index 89ab33b4f0..fc15c4c774 100644
--- a/challenge-268/ash/raku/ch-1.raku
+++ b/challenge-268/ash/raku/ch-1.raku
@@ -8,7 +8,6 @@
# 3
# No such number
-
my @tests =
([3, 7, 5], [9, 5, 7]),
([1, 2, 1], [5, 4, 4]),
@@ -21,7 +20,7 @@ for @tests -> (@a is copy, @b is copy) {
@b .= sort;
my $diff = @b[0] - @a[0];
- if (@a >>+>> $diff eqv @b) {
+ if @a >>+>> $diff eqv @b {
say $diff;
}
else {
diff --git a/challenge-268/ash/raku/ch-2.raku b/challenge-268/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..e830677306
--- /dev/null
+++ b/challenge-268/ash/raku/ch-2.raku
@@ -0,0 +1,27 @@
+# Task 2 of The Weekly Challenge 268
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-268/#TASK2
+
+# Test run:
+# $ raku ch-2.raku
+# [3 2 5 4]
+# [1 1 4 3 6 4 9 6]
+# [2 1 3 2]
+
+my @tests =
+ (2, 5, 3, 4),
+ (9, 4, 1, 3, 6, 4, 6, 1),
+ (1, 2, 2, 3);
+
+for @tests -> @test {
+ my @out;
+ for @test.sort -> $a, $b {
+ if $a > $b {
+ @out.push($a, $b);
+ }
+ else {
+ @out.push($b, $a);
+ }
+ }
+
+ say @out;
+}