aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-328/barroff/raku/ch-1.p639
-rw-r--r--challenge-329/barroff/raku/ch-1.p622
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);
+}