aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-319/barroff/raku/ch-1.p625
-rw-r--r--challenge-319/barroff/raku/ch-2.p620
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-319/barroff/raku/ch-1.p6 b/challenge-319/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..6d6514de2e
--- /dev/null
+++ b/challenge-319/barroff/raku/ch-1.p6
@@ -0,0 +1,25 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub word-count(@list --> Int) {
+ grep({ $_.lc ~~ / ^ (<[aeiou]><alpha>*|<alpha>*<[aeiou]>) $ / }, @list).elems;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 3;
+
+ is word-count(["unicode", "xml", "raku", "perl"]), 2,
+ 'works for ["unicode", "xml", "raku", "perl"]';
+ is word-count(["the", "weekly", "challenge"]), 2,
+ 'works for ["the", "weekly", "challenge"]';
+ is word-count(["perl", "python", "postgres"]), 0,
+ 'works for ["perl", "python", "postgres"]';
+}
+
+#| Take user provided words like "perl", "python", "postgres"
+multi sub MAIN(*@list) {
+ say word-count(@list);
+}
diff --git a/challenge-319/barroff/raku/ch-2.p6 b/challenge-319/barroff/raku/ch-2.p6
new file mode 100644
index 0000000000..72801027a9
--- /dev/null
+++ b/challenge-319/barroff/raku/ch-2.p6
@@ -0,0 +1,20 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub minimum-common(@array_1, @array_2 --> Int) {
+ my %intersection = (Set(@array_1) (&) Set(@array_2));
+ return %intersection ?? min(%intersection.keys).Int !! -1;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 3;
+
+ is minimum-common([1, 2, 3, 4], [3, 4, 5, 6]), 3,
+ 'works for "[1, 2, 3, 4], [3, 4, 5, 6]"';
+ is minimum-common([1, 2, 3], [2, 4]), 2, 'works for "[1, 2, 3], [2, 4]"';
+ is minimum-common([1, 2, 3, 4], [5, 6, 7, 8]), -1,
+ 'works for "[1, 2, 3, 4], [5, 6, 7, 8]"';
+}