From c82e364437a47f05de2b50c4c4b948063f00bb72 Mon Sep 17 00:00:00 2001 From: Andrey Shitov Date: Mon, 30 Jun 2025 08:43:17 +0300 Subject: Week 328, solutions in Raky by @ash --- challenge-328/ash/raku/ch-1.raku | 20 ++++++++++++++++++++ challenge-328/ash/raku/ch-2.raku | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 challenge-328/ash/raku/ch-1.raku create mode 100644 challenge-328/ash/raku/ch-2.raku diff --git a/challenge-328/ash/raku/ch-1.raku b/challenge-328/ash/raku/ch-1.raku new file mode 100644 index 0000000000..10598aee67 --- /dev/null +++ b/challenge-328/ash/raku/ch-1.raku @@ -0,0 +1,20 @@ +# Task 1 of The Weekly Challenge 328 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-328/#TASK1 + +say replace('a?z'); # abz +say replace('pe?k'); # peak +say replace('gra?te'); # grabte + +# The task says to "replace all '?', so:" +say replace('a?z?'); # abzc + +sub replace($str is copy) { + my @options = ['a'..'z'] (-) $str.comb; + my $option = @options.sort.first.key; + + $str ~~ s/'?'/$option/; + + $str = replace($str) if $str ~~ /'?'/; + + return $str; +} diff --git a/challenge-328/ash/raku/ch-2.raku b/challenge-328/ash/raku/ch-2.raku new file mode 100644 index 0000000000..bbaaf15eb9 --- /dev/null +++ b/challenge-328/ash/raku/ch-2.raku @@ -0,0 +1,16 @@ +# Task 2 of The Weekly Challenge 328 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-328/#TASK2 + +say good-string('WeEeekly'); # Weekly +say good-string('aBbAdD'); # abc +say good-string('abc'); # (empty) + +sub good-string($str) { + my $s = $str; + $s ~~ s:g/(<:Ll>)(<:Lu>)/{ $0 eq $1.lc ?? '' !! "$0$1" }/; + $s ~~ s:g/(<:Lu>)(<:Ll>)/{ $0.lc eq $1 ?? '' !! "$0$1" }/; + + return "[$s]" if $s eq $str; + return good-string($s) if $s.lc ~~ /(.) $0/; + return $s; +} -- cgit