From 7e72cc76faf02364451321e347b52b678c0e81e5 Mon Sep 17 00:00:00 2001 From: BarrOff <58253563+BarrOff@users.noreply.github.com> Date: Sun, 13 Jul 2025 22:30:41 +0200 Subject: feat: add solution for challenge 328 from BarrOff --- challenge-328/barroff/raku/ch-1.p6 | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 challenge-328/barroff/raku/ch-1.p6 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); +} -- cgit From a1324e824266436465d1c09fae11710892ac240f Mon Sep 17 00:00:00 2001 From: BarrOff <58253563+BarrOff@users.noreply.github.com> Date: Sun, 13 Jul 2025 22:31:06 +0200 Subject: feat: add solution for challenge 329 from BarrOff --- challenge-329/barroff/raku/ch-1.p6 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 challenge-329/barroff/raku/ch-1.p6 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(/+/, :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); +} -- cgit