aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarrOff <58253563+BarrOff@users.noreply.github.com>2023-03-13 23:39:45 +0100
committerBarrOff <58253563+BarrOff@users.noreply.github.com>2023-03-13 23:39:45 +0100
commit51d542c7f56f27b5f8f32a006f8309d06c0c5f5f (patch)
treed783df91883581fd1bbc26e14a740c69d8bd0065
parent2cb00557ab6964716d9bd448dd2067875520e1c9 (diff)
downloadperlweeklychallenge-club-51d542c7f56f27b5f8f32a006f8309d06c0c5f5f.tar.gz
perlweeklychallenge-club-51d542c7f56f27b5f8f32a006f8309d06c0c5f5f.tar.bz2
perlweeklychallenge-club-51d542c7f56f27b5f8f32a006f8309d06c0c5f5f.zip
feat: add solutions for challenge 207 from BarrOff
-rw-r--r--challenge-207/barroff/blog.txt1
-rw-r--r--challenge-207/barroff/raku/ch-1.raku30
-rw-r--r--challenge-207/barroff/raku/ch-2.raku25
3 files changed, 56 insertions, 0 deletions
diff --git a/challenge-207/barroff/blog.txt b/challenge-207/barroff/blog.txt
new file mode 100644
index 0000000000..ea32d1d841
--- /dev/null
+++ b/challenge-207/barroff/blog.txt
@@ -0,0 +1 @@
+https://barroff.codeberg.page/posts/2023/2023-03-12-challenge-207/
diff --git a/challenge-207/barroff/raku/ch-1.raku b/challenge-207/barroff/raku/ch-1.raku
new file mode 100644
index 0000000000..432b939b23
--- /dev/null
+++ b/challenge-207/barroff/raku/ch-1.raku
@@ -0,0 +1,30 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub keyboard-word(Str $word --> Bool) {
+ my $row1 = /:i <[qwertyuiop]> /;
+ my $row2 = /:i <[asdfghjkl]> /;
+ my $row3 = /:i <[zxcvbnm]> /;
+ $word ~~ /^ [<$row1>+ | <$row2>+ | <$row3>+] $ / ?? True !! False;
+}
+
+sub keyboard-word-list(Str @words --> Array[Str]) {
+ my Str @kwords = grep(&keyboard-word, @words);
+ return @kwords
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 2;
+
+ is keyboard-word-list(Array[Str].new(["Hello","Alaska","Dad","Peace"])), ("Alaska", "Dad"), 'works for ("Hello","Alaska","Dad","Peace")';
+ is keyboard-word-list(Array[Str].new(["OMG","Bye"])), (), 'works for ("OMG","Bye")';
+}
+
+#| Take user provided list like: Hello how are you asdf
+multi sub MAIN(*@elements where @elements.elems ≥ 1 && all(@elements) ~~ /^<[a..zA..Z]>+$/) {
+ my Str @str-elements = @elements;
+ say keyboard-word-list(@str-elements);
+}
diff --git a/challenge-207/barroff/raku/ch-2.raku b/challenge-207/barroff/raku/ch-2.raku
new file mode 100644
index 0000000000..5dc8252ad2
--- /dev/null
+++ b/challenge-207/barroff/raku/ch-2.raku
@@ -0,0 +1,25 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub h-index(Int @citations --> Int) {
+ my Int @sorted-citations = sort(@citations);
+ my Int $index = 2;
+ $index++ while @sorted-citations[* - $index] ≥ $index;
+ return $index - 1;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 2;
+
+ is h-index(Array[Int].new([10,8,5,4,3])), 4, 'works for (10,8,5,4,3)';
+ is h-index(Array[Int].new([25,8,5,3,3])), 3, 'works for (25,8,5,3,3)';
+}
+
+#| Take user provided list like 1 2 2 3
+multi sub MAIN(*@elements where @elements.elems ≥ 1 && all(@elements) ~~ /^0?<[1..9]><[0..9]>*$/) {
+ my Int @int-elements = @elements;
+ say "The h-index of ({@int-elements}) is: {h-index(@int-elements)}";
+}