From 3ec3339c5ee23a1857af3ce94e1bed49667627b8 Mon Sep 17 00:00:00 2001 From: BarrOff <58253563+BarrOff@users.noreply.github.com> Date: Sun, 16 Jul 2023 22:37:45 +0200 Subject: feat: add solutions for challenge 225 from BarrOff --- challenge-225/barroff/perl/ch-1.pl | 29 +++++++++++++++++++++++++++++ challenge-225/barroff/raku/ch-1.raku | 31 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 challenge-225/barroff/perl/ch-1.pl create mode 100644 challenge-225/barroff/raku/ch-1.raku 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/ ( \s ) /).elems}, @words)) + 1; + # max(map({($_ ~~ m:g/<|w> ( \s ) <|w>/).elems}, @words)) + 1; + max(map({($_ ~~ m:g/>> ( \s ) <