aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Krňávek <Jan.Krnavek@gmail.com>2023-03-12 20:43:33 +0100
committerJan Krňávek <Jan.Krnavek@gmail.com>2023-03-12 20:43:33 +0100
commitad1fb7cc136aac33cf54c1fdfe865fc3db06d29e (patch)
tree72e95293236e51075c114e78edef7743991bc073
parent1f9e919800ebc28992c10467f2e9a2d1afe90169 (diff)
downloadperlweeklychallenge-club-ad1fb7cc136aac33cf54c1fdfe865fc3db06d29e.tar.gz
perlweeklychallenge-club-ad1fb7cc136aac33cf54c1fdfe865fc3db06d29e.tar.bz2
perlweeklychallenge-club-ad1fb7cc136aac33cf54c1fdfe865fc3db06d29e.zip
solutions week 207
-rw-r--r--challenge-207/wambash/raku/ch-1.raku20
-rw-r--r--challenge-207/wambash/raku/ch-2.raku21
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-207/wambash/raku/ch-1.raku b/challenge-207/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..a89cd67974
--- /dev/null
+++ b/challenge-207/wambash/raku/ch-1.raku
@@ -0,0 +1,20 @@
+#!/usr/bin/env raku
+
+my @*keyboard := <qwertyuiop asdfghjkl zxcvbnm>».comb;
+
+sub keyboard-word (+@words,:@keyboard=@*keyboard) {
+ my @keyboard-rows = @keyboard.map: { rx:i/^ @^row + $/ };
+ my &keyboard-regex = rx/@keyboard-rows/;
+ @words.grep: *.contains: &keyboard-regex #or @keyboard-rows.any;
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is-deeply keyboard-word(<Hello Alaska Dad Peace>),<Alaska Dad>;
+ is-deeply keyboard-word(<OMG Bye>), $();
+ done-testing;
+}
+
+multi MAIN (*@words,:$keyboard=@*keyboard) {
+ say keyboard-word @words, :$keyboard
+}
diff --git a/challenge-207/wambash/raku/ch-2.raku b/challenge-207/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..96556cb0fe
--- /dev/null
+++ b/challenge-207/wambash/raku/ch-2.raku
@@ -0,0 +1,21 @@
+#!/usr/bin/env raku
+
+sub h-index ( +@citation ) {
+ @citation
+ andthen 0, |$_
+ andthen .reduce: { $^count < $^n ?? $^count+1 !! last }
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is h-index(10,8,5,4,3), 4;
+ is h-index(25,8,5,3,3), 3;
+ is h-index(10 xx 20), 10;
+ is h-index(9...1), 5;
+ is h-index(9,7,6,2,1), 3;
+ done-testing;
+}
+
+multi MAIN ( *@citation ) {
+ say h-index @citation
+}