diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-07-16 22:12:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-16 22:12:43 +0100 |
| commit | aeb26610cb42c7ee5dc62ed1b8e006f0d25a481d (patch) | |
| tree | 98764c38a33f889c105b862caf3e579c639dd5a4 | |
| parent | 97dd19e7aae537c68ea5c595122fa7bf56418d6e (diff) | |
| parent | 1771f9b0c0f3a584dc5d10845d5ea67759e4d827 (diff) | |
| download | perlweeklychallenge-club-aeb26610cb42c7ee5dc62ed1b8e006f0d25a481d.tar.gz perlweeklychallenge-club-aeb26610cb42c7ee5dc62ed1b8e006f0d25a481d.tar.bz2 perlweeklychallenge-club-aeb26610cb42c7ee5dc62ed1b8e006f0d25a481d.zip | |
Merge pull request #8388 from Util/c225
Add TWC 225 solutions by Bruce Gray (Raku only).
| -rw-r--r-- | challenge-225/bruce-gray/raku/ch-1.raku | 17 | ||||
| -rw-r--r-- | challenge-225/bruce-gray/raku/ch-2.raku | 22 |
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-225/bruce-gray/raku/ch-1.raku b/challenge-225/bruce-gray/raku/ch-1.raku new file mode 100644 index 0000000000..d0f9b529cb --- /dev/null +++ b/challenge-225/bruce-gray/raku/ch-1.raku @@ -0,0 +1,17 @@ +sub task1 (@sentences --> UInt) { + return @sentences.map( *.words.elems ).max; +} + +# Shorter: +# my &task1 = *».words».elems.max; + + +my @tests = + ( 8, ( 'Perl and Raku belong to the same family.', 'I love Perl.', 'The Perl and Raku Conference.', ) ), + ( 7, ( 'The Weekly Challenge.', 'Python is the most popular guest language.', 'Team PWC has over 300 members.' ) ), +; +use Test; +plan +@tests; +for @tests -> ( $expected, @sentences ) { + is task1(@sentences), $expected; +} diff --git a/challenge-225/bruce-gray/raku/ch-2.raku b/challenge-225/bruce-gray/raku/ch-2.raku new file mode 100644 index 0000000000..c017f23950 --- /dev/null +++ b/challenge-225/bruce-gray/raku/ch-2.raku @@ -0,0 +1,22 @@ +sub abs_diff { abs $^x - $^y } +sub partial_sum_0 { 0, |[\+] @^a.head(*-1) } + +sub task2 ( Int @ns --> Array ) { + + my @left = partial_sum_0(@ns); + my @right = partial_sum_0(@ns.reverse).reverse; + + return @left »[&abs_diff]« @right; +} + + +my @tests = + ( (10, 4, 8, 3) , (15, 1, 11, 22) ), + ( (1,) , (0,) ), + ( (1, 2, 3, 4, 5) , (14, 11, 6, 1, 10) ), +; +use Test; +plan +@tests; +for @tests -> ( @in, @expected ) { + is-deeply task2( Array[Int].new(@in) ), @expected.Array; +} |
