aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-07-22 09:30:42 +0100
committerGitHub <noreply@github.com>2024-07-22 09:30:42 +0100
commit03e2e7cae2fc04901ad15f2207af10b0f118e2f9 (patch)
tree70d6177fe095ed33aa6dc7ba639271f20829b7d2
parent35bd04420628aa394a8fc9ece79140786a4bac18 (diff)
parent9b1b7a71043c6d6cbc702bd75fbb78e16509a698 (diff)
downloadperlweeklychallenge-club-03e2e7cae2fc04901ad15f2207af10b0f118e2f9.tar.gz
perlweeklychallenge-club-03e2e7cae2fc04901ad15f2207af10b0f118e2f9.tar.bz2
perlweeklychallenge-club-03e2e7cae2fc04901ad15f2207af10b0f118e2f9.zip
Merge pull request #10467 from andemark/challenge-279
Challenge 279 Solutions (Raku)
-rw-r--r--challenge-279/mark-anderson/raku/ch-1.raku16
-rw-r--r--challenge-279/mark-anderson/raku/ch-2.raku41
2 files changed, 57 insertions, 0 deletions
diff --git a/challenge-279/mark-anderson/raku/ch-1.raku b/challenge-279/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..09708331c1
--- /dev/null
+++ b/challenge-279/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,16 @@
+#!/usr/bin/env raku
+use Test;
+
+is sort-letters([<R E P L>],
+ [<3 2 1 4>]), 'PERL';
+
+is sort-letters([<A U R K>],
+ [<2 4 1 3>]), 'RAKU';
+
+is sort-letters([<O H Y N P T>],
+ [<5 4 2 6 1 3>]), 'PYTHON';
+
+sub sort-letters(@letters, @weights)
+{
+ [~] %(@weights Z=> @letters){1..@weights}
+}
diff --git a/challenge-279/mark-anderson/raku/ch-2.raku b/challenge-279/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..1251f5a5d3
--- /dev/null
+++ b/challenge-279/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,41 @@
+#!/usr/bin/env raku
+use HTTP::UserAgent;
+use DOM::Tiny;
+use Test;
+
+nok split-string('perl'), '1 vowel';
+ok split-string('book'), '2 vowels';
+ok split-string('good morning'), '4 vowels';
+ok split-string('anybody beyond mystic'), '8 vowels';
+
+sub split-string($str is copy)
+{
+ $str .= lc;
+ my $count = ($str ~~ m:g/ <[aeiou]> /).elems;
+
+ for $str.words.grep({ .contains('y') }) -> $word
+ {
+ if $word.comb.contains(none(<a e i o u>))
+ {
+ $count += ($word ~~ m:g/y/).elems;
+ next
+ }
+
+ my $ua = HTTP::UserAgent.new;
+ my $res = $ua.get("https://www.merriam-webster.com/dictionary/$word");
+
+ die $res.status-line unless $res.is-success;
+
+ my $dom = DOM::Tiny.parse($res.content);
+ my @syllables = $dom.at('.word-syllables-entry')
+ .text.split("\x[00B7]\x[200B]");
+
+ for @syllables
+ {
+ next unless .contains('y');
+ $count += (.comb.indices('y').grep(* > 0)).elems
+ }
+ }
+
+ return $count %% 2
+}