aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-207/carlos-oliveira/raku/ch-1.raku22
-rw-r--r--challenge-207/carlos-oliveira/raku/ch-2.raku14
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-207/carlos-oliveira/raku/ch-1.raku b/challenge-207/carlos-oliveira/raku/ch-1.raku
new file mode 100644
index 0000000000..1632a777c2
--- /dev/null
+++ b/challenge-207/carlos-oliveira/raku/ch-1.raku
@@ -0,0 +1,22 @@
+use Test;
+
+sub extract-keyboard-words (@words where all($_) ~~ Str:D) {
+ my @keyboard-rows = (
+ Set.new(<q w e r t y u i o p>),
+ Set.new(<a s d f g h j k l>),
+ Set.new(<z x c v b n m>)
+ );
+
+ gather {
+ for @words -> $raw-word {
+ my $word = lc $raw-word;
+ for @keyboard-rows -> %keyboard-row {
+ take $raw-word and next if all(%keyboard-row{$word.comb('')});
+ }
+ }
+ }
+}
+
+is extract-keyboard-words(["Hello", "Alaska", "Dad", "Peace"]), ["Alaska", "Dad"];
+is extract-keyboard-words(["OMG", "Bye"]), [];
+is extract-keyboard-words(["ABC"]), [];
diff --git a/challenge-207/carlos-oliveira/raku/ch-2.raku b/challenge-207/carlos-oliveira/raku/ch-2.raku
new file mode 100644
index 0000000000..a79b57c83c
--- /dev/null
+++ b/challenge-207/carlos-oliveira/raku/ch-2.raku
@@ -0,0 +1,14 @@
+use Test;
+
+sub h-index (@citations where all($_) ~~ Int:D) {
+ my $h-index = 0;
+ my $some-invalid = @citations.sort.reverse.first: { $_ < ++$h-index };
+ return $some-invalid ?? $h-index - 1 !! $h-index;
+}
+
+is h-index([10, 8, 5, 4, 3]), 4;
+is h-index([25, 8, 5, 3, 3]), 3;
+is h-index([7, 7, 7]), 3;
+is h-index([2, 1]), 1;
+is h-index([1]), 1;
+is h-index([]), 0;