aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-07-08 16:59:21 +0100
committerGitHub <noreply@github.com>2025-07-08 16:59:21 +0100
commit996e12deb3a31add42baa3ee4a673b23af710f4e (patch)
tree16941111feb50d961d7f3d072983587ae924bda0
parent669c0947e214eb1b175b0aadd4147220787b6711 (diff)
parent4e7df4158a2ddce14748bb9acda5bd9576137111 (diff)
downloadperlweeklychallenge-club-996e12deb3a31add42baa3ee4a673b23af710f4e.tar.gz
perlweeklychallenge-club-996e12deb3a31add42baa3ee4a673b23af710f4e.tar.bz2
perlweeklychallenge-club-996e12deb3a31add42baa3ee4a673b23af710f4e.zip
Merge pull request #12298 from ash/master
Week 329, solutions by @ash in Raku
-rw-r--r--challenge-329/ash/raku/ch-1.raku14
-rw-r--r--challenge-329/ash/raku/ch-2.raku38
2 files changed, 52 insertions, 0 deletions
diff --git a/challenge-329/ash/raku/ch-1.raku b/challenge-329/ash/raku/ch-1.raku
new file mode 100644
index 0000000000..593f5af080
--- /dev/null
+++ b/challenge-329/ash/raku/ch-1.raku
@@ -0,0 +1,14 @@
+# Task 1 of The Weekly Challenge 329
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-329/#TASK1
+
+say find-distinct-numbers('the1weekly2challenge2');
+say find-distinct-numbers('go21od1lu5c7k');
+say find-distinct-numbers('4p3e2r1l');
+
+sub find-distinct-numbers($str) {
+ (
+ (
+ $str ~~ m:g/ \d+ /
+ )>>.Str
+ ).unique
+}
diff --git a/challenge-329/ash/raku/ch-2.raku b/challenge-329/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..29bdff0469
--- /dev/null
+++ b/challenge-329/ash/raku/ch-2.raku
@@ -0,0 +1,38 @@
+# Task 2 of The Weekly Challenge 329
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-329/#TASK2
+
+say longest-substring('YaaAh'); # aaA
+say longest-substring('cC'); # cC
+say longest-substring('A'); # <None>
+
+# Some additional tests:
+say longest-substring('xuWwcC'); # WwcC
+say longest-substring('YaaAhbbBB'); # bbBB
+say longest-substring('YaaAhbBB'); # aaA being the first one, but bBB also matches
+
+sub longest-substring($str) {
+ my @nice;
+
+ for 0 ..^ $str.chars -> $start {
+ for $start + 1 .. $str.chars -> $end {
+ my $substr = $str.substr($start, $end - $start);
+
+ push @nice, $substr if is-nice($substr);
+ }
+ }
+
+ return '<None>' unless @nice;
+
+ my $max-len = @nice.map(*.chars).max;
+
+ return (@nice.grep: *.chars == $max-len)[0]; # Only returns a single match
+
+ sub is-nice($str) {
+ my $chars = $str.comb.Bag;
+ my @lc = $chars.keys.grep: * ~~ /<:Lower>/;
+ my @uc = $chars.keys.grep: * ~~ /<:Upper>/;
+ @uc>>.=lc;
+
+ return @lc.Set eqv @uc.Set;
+ }
+}