aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Shitov <mail@andreyshitov.com>2025-05-12 16:35:29 +0200
committerAndrew Shitov <mail@andreyshitov.com>2025-05-12 16:35:29 +0200
commit646c43333fbe08f69292d3a6b151f792f4e55715 (patch)
tree30e5b5e799f7d83d8c7d63ccb2e4eaae112ad140
parent62f1ccaddfc5a65501df9cfdf528d28927fef410 (diff)
downloadperlweeklychallenge-club-646c43333fbe08f69292d3a6b151f792f4e55715.tar.gz
perlweeklychallenge-club-646c43333fbe08f69292d3a6b151f792f4e55715.tar.bz2
perlweeklychallenge-club-646c43333fbe08f69292d3a6b151f792f4e55715.zip
Solutions of Week 321 by @ash in Raku
-rw-r--r--challenge-321/ash/raku/ch-1.raku20
-rw-r--r--challenge-321/ash/raku/ch-2.raku19
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-321/ash/raku/ch-1.raku b/challenge-321/ash/raku/ch-1.raku
new file mode 100644
index 0000000000..7e7cbb3642
--- /dev/null
+++ b/challenge-321/ash/raku/ch-1.raku
@@ -0,0 +1,20 @@
+# Task 1 of the Weekly Challenge 321
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-321/#TASK1
+
+my @nums = 1, 2, 4, 3, 5, 6; # 1
+# my @nums = 0, 2, 4, 8, 3, 5; # 2
+# my @nums = 7, 3, 1, 0, 5, 9; # 2
+
+my @avg = gather {
+ while (@nums) {
+ my $min = @nums.min;
+ my $max = @nums.max;
+
+ my $avg = ($min + $max) / 2;
+ take $avg;
+
+ @nums.=grep: * ∉ (@nums.min, @nums.max);
+ }
+}
+
+say @avg.unique.elems;
diff --git a/challenge-321/ash/raku/ch-2.raku b/challenge-321/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..974cdc314b
--- /dev/null
+++ b/challenge-321/ash/raku/ch-2.raku
@@ -0,0 +1,19 @@
+# Task 2 of the Weekly Challenge 321
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-321/#TASK2
+
+my $str1 = 'ab#c';
+my $str2 = 'ad#c'; # True
+
+# my $str1 = 'ab##';
+# my $str2 = 'a#b#'; # True
+
+# my $str1 = 'a#b';
+# my $str2 = 'c'; # False
+
+say process($str1) eq process($str2);
+
+sub process($s is copy) {
+ $s ~~ s/.\#// while $s ~~ /.\#/;
+
+ return $s;
+} \ No newline at end of file