aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-07-16 21:55:19 +0100
committerGitHub <noreply@github.com>2023-07-16 21:55:19 +0100
commit97dd19e7aae537c68ea5c595122fa7bf56418d6e (patch)
treeb290fd077a9618248af17a2efdeb15ddfe7fe8cb
parent469bd9b7ae54353ccd57416c6e3a26111c8d72bf (diff)
parent3ec3339c5ee23a1857af3ce94e1bed49667627b8 (diff)
downloadperlweeklychallenge-club-97dd19e7aae537c68ea5c595122fa7bf56418d6e.tar.gz
perlweeklychallenge-club-97dd19e7aae537c68ea5c595122fa7bf56418d6e.tar.bz2
perlweeklychallenge-club-97dd19e7aae537c68ea5c595122fa7bf56418d6e.zip
Merge pull request #8387 from BarrOff/barroff-225
feat: add solutions for challenge 225 from BarrOff
-rw-r--r--challenge-225/barroff/perl/ch-1.pl29
-rw-r--r--challenge-225/barroff/raku/ch-1.raku31
2 files changed, 60 insertions, 0 deletions
diff --git a/challenge-225/barroff/perl/ch-1.pl b/challenge-225/barroff/perl/ch-1.pl
new file mode 100644
index 0000000000..c9051906ad
--- /dev/null
+++ b/challenge-225/barroff/perl/ch-1.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+
+use v5.36;
+use List::Util qw( max );
+
+sub max_words (@sentences) {
+ max( map( scalar( $_ = () = $_ =~ /\b(\s)\b/g ), @sentences ) ) + 1;
+}
+
+#| Run test cases
+sub MAIN() {
+ use Test2::V0 qw( is plan );
+ plan 2;
+
+ is max_words(
+ "Perl and Raku belong to the same family.",
+ "I love Perl.",
+ "The Perl and Raku Conference."
+ ),
+ 8, 'works for first sentence list';
+ is max_words(
+ "The Weekly Challenge.",
+ "Python is the most popular guest language.",
+ "Team PWC has over 300 members."
+ ),
+ 7, 'works for second sentence list';
+}
+
+MAIN();
diff --git a/challenge-225/barroff/raku/ch-1.raku b/challenge-225/barroff/raku/ch-1.raku
new file mode 100644
index 0000000000..7fa60f303c
--- /dev/null
+++ b/challenge-225/barroff/raku/ch-1.raku
@@ -0,0 +1,31 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub max-words(Str:D @words --> Int) {
+ # max(map({($_ ~~ m:g/<wb> ( \s ) <wb>/).elems}, @words)) + 1;
+ # max(map({($_ ~~ m:g/<|w> ( \s ) <|w>/).elems}, @words)) + 1;
+ max(map({($_ ~~ m:g/>> ( \s ) <</).elems}, @words)) + 1;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 2;
+
+ is max-words(Array[Str:D].new(('Perl and Raku belong to the same family.',
+ 'I love Perl.',
+ 'The Perl and Raku Conference.'))),
+ 8, 'works for first sentence list';
+ is max-words(Array[Str:D].new(('The Weekly Challenge.',
+ 'Python is the most popular guest language.',
+ 'Team PWC has over 300 members.'))),
+ 7, 'works for second sentence list';
+}
+
+#| Take user provided list like Perl Rust Raku
+multi sub MAIN(*@words where @words.elems ≥ 1) {
+ my Str @str-words = @words;
+ say max-words(@str-words);
+}
+