From 0d565674f19af4f86b87c5ace9e1cc547629650e Mon Sep 17 00:00:00 2001 From: Jan Krňávek Date: Sun, 6 Jul 2025 10:55:43 +0200 Subject: solutions week 328 --- challenge-328/wambash/raku/ch-1.raku | 31 +++++++++++++++++++++++++++++++ challenge-328/wambash/raku/ch-2.raku | 18 ++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 challenge-328/wambash/raku/ch-1.raku create mode 100644 challenge-328/wambash/raku/ch-2.raku diff --git a/challenge-328/wambash/raku/ch-1.raku b/challenge-328/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..343900b676 --- /dev/null +++ b/challenge-328/wambash/raku/ch-1.raku @@ -0,0 +1,31 @@ +#!/usr/bin/env raku + + +sub replace-iter ($str) { + $str + andthen .subst: / <-[a]> <( '?' )> <-[a]> /, 'a', :g + andthen .subst: / a <( '?' )> b | b <( '?' )> a /, 'c', :g + andthen .subst: / a <( '?' | '?' )> a /, 'b' +} + +sub replace-all ($str) { + $str, &replace-iter ... !*.contains('?') + andthen .tail +} + +multi MAIN (Bool :test($)!) { + use Test; + is replace-iter('a?z'), 'abz'; + is-deeply replace-all('a?z'), 'abz'; + is-deeply replace-all('a???b'), 'abacb'; + is-deeply replace-all('???a'), 'baba'; + is-deeply replace-all('a??a'), 'abca'; + is replace-iter('pe?k'), 'peak'; + is replace-iter('gra?te'), 'grabte'; + is replace-iter('a?b'), 'acb'; + done-testing; +} + +multi MAIN ($str) { + say replace-all $str; +} diff --git a/challenge-328/wambash/raku/ch-2.raku b/challenge-328/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..cf5a4737a9 --- /dev/null +++ b/challenge-328/wambash/raku/ch-2.raku @@ -0,0 +1,18 @@ +#!/usr/bin/env raku + +sub good-string (+str) { + str.subst: / (<:Lu>) <~~>* <{lc $0}> | (<:Ll>) <~~>* <{uc $0}> /, :g +} + +multi MAIN (Bool :test($)!) { + use Test; + is good-string('WeEeekly'), 'Weekly'; + is good-string('abBAdD'), ''; + is good-string('abc'), 'abc'; + is good-string('xAayeBCcdDbEz'), 'xyz'; + done-testing; +} + +multi MAIN ($str) { + say good-string $str; +} -- cgit