diff options
| -rw-r--r-- | challenge-225/barroff/perl/ch-1.pl | 29 | ||||
| -rw-r--r-- | challenge-225/barroff/raku/ch-1.raku | 31 |
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); +} + |
