aboutsummaryrefslogtreecommitdiff
path: root/challenge-321/ash
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2025-05-15 16:45:20 -0400
committerGitHub <noreply@github.com>2025-05-15 16:45:20 -0400
commitefc2a652edb6436965e12883bedf035ea081284d (patch)
tree7e9940d4f72fe1e8d984b3746af2d30dff96330b /challenge-321/ash
parent6886bd3e06ccf8b0a564f3c434cd53131d126f70 (diff)
parented7588dadb77d63adca3d3aefc6cd325164e0947 (diff)
downloadperlweeklychallenge-club-efc2a652edb6436965e12883bedf035ea081284d.tar.gz
perlweeklychallenge-club-efc2a652edb6436965e12883bedf035ea081284d.tar.bz2
perlweeklychallenge-club-efc2a652edb6436965e12883bedf035ea081284d.zip
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-321/ash')
-rw-r--r--challenge-321/ash/README1
-rw-r--r--challenge-321/ash/raku/ch-1.raku20
-rw-r--r--challenge-321/ash/raku/ch-2.raku19
3 files changed, 40 insertions, 0 deletions
diff --git a/challenge-321/ash/README b/challenge-321/ash/README
new file mode 100644
index 0000000000..318b1bfb41
--- /dev/null
+++ b/challenge-321/ash/README
@@ -0,0 +1 @@
+Solutions by Andrew Shitov
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..904586b279
--- /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;
+}