diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-14 00:26:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-14 00:26:21 +0100 |
| commit | d2e3420d1d0d4efaf9abca5e5b1c9a2f70d912d1 (patch) | |
| tree | dfbe01c8faca038354c82e647ee0b15e9f6fe53a | |
| parent | 119c66a51130e37ea4aaa01a646740651d533800 (diff) | |
| parent | a1324e824266436465d1c09fae11710892ac240f (diff) | |
| download | perlweeklychallenge-club-d2e3420d1d0d4efaf9abca5e5b1c9a2f70d912d1.tar.gz perlweeklychallenge-club-d2e3420d1d0d4efaf9abca5e5b1c9a2f70d912d1.tar.bz2 perlweeklychallenge-club-d2e3420d1d0d4efaf9abca5e5b1c9a2f70d912d1.zip | |
Merge pull request #12335 from BarrOff/barroff-329
add solutions for challenges 328 and 329 from BarrOff
| -rw-r--r-- | challenge-328/barroff/raku/ch-1.p6 | 39 | ||||
| -rw-r--r-- | challenge-329/barroff/raku/ch-1.p6 | 22 |
2 files changed, 61 insertions, 0 deletions
diff --git a/challenge-328/barroff/raku/ch-1.p6 b/challenge-328/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..700f81ed74 --- /dev/null +++ b/challenge-328/barroff/raku/ch-1.p6 @@ -0,0 +1,39 @@ +#!/usr/bin/env raku + +use v6.d; + +sub replace-all-q(Str $str --> Str) { + return $str unless $str.contains('?'); + my @chars = $str.comb; + if @chars[0] eq '?' { + @chars[0] = @chars[1] eq 'a' ?? 'b' !! 'a'; + } + for 1..@chars.elems - 2 { + if @chars[$_] eq '?' { + my $surroundings = Set(@chars[$_ - 1], @chars[$_ + 1]); + if 'a' ∉ $surroundings { + @chars[$_] = 'a'; + } elsif 'b' ∉ $surroundings { + @chars[$_] = 'b'; + } else { + @chars[$_] = 'c'; + } + } + } + @chars.join; +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 3; + + is replace-all-q("a?z"), "abz", 'works for "a?z"'; + is replace-all-q("pe?k"), "peak", 'works for "pe?k"'; + is replace-all-q("gra?te"), "grabte", 'works for "gra?te"'; +} + +#| Take user provided string like "a?z" +multi sub MAIN(Str $str) { + say replace-all-q($str); +} diff --git a/challenge-329/barroff/raku/ch-1.p6 b/challenge-329/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..0cd2e1d1c7 --- /dev/null +++ b/challenge-329/barroff/raku/ch-1.p6 @@ -0,0 +1,22 @@ +#!/usr/bin/env raku + +use v6.d; + +sub counter-integers(Str $str --> Seq) { + $str.split(/<lower>+/, :skip-empty).unique; +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 3; + + is counter-integers("the1weekly2challenge2"), (1, 2), 'works for "the1weekly2challenge2"'; + is counter-integers("go21od1lu5c7k"), (21, 1, 5, 7), 'works for "go21od1lu5c7k"'; + is counter-integers("4p3e2r1l"), (4, 3, 2, 1), 'works for "4p3e2r1l"'; +} + +#| Take user provided string like "the1weekly2challenge2" +multi sub MAIN(Str $str) { + say counter-integers($str); +} |
