diff options
| author | Andrey Shitov <ash@Andreys-iMac.local> | 2025-06-30 08:43:17 +0300 |
|---|---|---|
| committer | Andrey Shitov <ash@Andreys-iMac.local> | 2025-06-30 08:43:17 +0300 |
| commit | c82e364437a47f05de2b50c4c4b948063f00bb72 (patch) | |
| tree | cf6f1d15ac42ffa267abc9d3d7caac5d019b0c97 | |
| parent | 7daf92e1dd4a2726fc578e87b6364ba4db3d5ad9 (diff) | |
| download | perlweeklychallenge-club-c82e364437a47f05de2b50c4c4b948063f00bb72.tar.gz perlweeklychallenge-club-c82e364437a47f05de2b50c4c4b948063f00bb72.tar.bz2 perlweeklychallenge-club-c82e364437a47f05de2b50c4c4b948063f00bb72.zip | |
Week 328, solutions in Raky by @ash
| -rw-r--r-- | challenge-328/ash/raku/ch-1.raku | 20 | ||||
| -rw-r--r-- | challenge-328/ash/raku/ch-2.raku | 16 |
2 files changed, 36 insertions, 0 deletions
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; +} |
