diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-05-06 09:24:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-06 09:24:19 +0100 |
| commit | 101413eaf7feacc251175b540495ac8f2ccd3f73 (patch) | |
| tree | 735d8f428679990da97e791e7e8c219e8608ebef | |
| parent | 8de256fb30eb34b015a777387977c107fd350d74 (diff) | |
| parent | e65d7116209cfcf71dad1e4654cd07bf858d142c (diff) | |
| download | perlweeklychallenge-club-101413eaf7feacc251175b540495ac8f2ccd3f73.tar.gz perlweeklychallenge-club-101413eaf7feacc251175b540495ac8f2ccd3f73.tar.bz2 perlweeklychallenge-club-101413eaf7feacc251175b540495ac8f2ccd3f73.zip | |
Merge pull request #11973 from BarrOff/barroff-319
feat: add solutions for challenge 319 from BarrOff
| -rw-r--r-- | challenge-319/barroff/raku/ch-1.p6 | 25 | ||||
| -rw-r--r-- | challenge-319/barroff/raku/ch-2.p6 | 20 |
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-319/barroff/raku/ch-1.p6 b/challenge-319/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..6d6514de2e --- /dev/null +++ b/challenge-319/barroff/raku/ch-1.p6 @@ -0,0 +1,25 @@ +#!/usr/bin/env raku + +use v6.d; + +sub word-count(@list --> Int) { + grep({ $_.lc ~~ / ^ (<[aeiou]><alpha>*|<alpha>*<[aeiou]>) $ / }, @list).elems; +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 3; + + is word-count(["unicode", "xml", "raku", "perl"]), 2, + 'works for ["unicode", "xml", "raku", "perl"]'; + is word-count(["the", "weekly", "challenge"]), 2, + 'works for ["the", "weekly", "challenge"]'; + is word-count(["perl", "python", "postgres"]), 0, + 'works for ["perl", "python", "postgres"]'; +} + +#| Take user provided words like "perl", "python", "postgres" +multi sub MAIN(*@list) { + say word-count(@list); +} diff --git a/challenge-319/barroff/raku/ch-2.p6 b/challenge-319/barroff/raku/ch-2.p6 new file mode 100644 index 0000000000..72801027a9 --- /dev/null +++ b/challenge-319/barroff/raku/ch-2.p6 @@ -0,0 +1,20 @@ +#!/usr/bin/env raku + +use v6.d; + +sub minimum-common(@array_1, @array_2 --> Int) { + my %intersection = (Set(@array_1) (&) Set(@array_2)); + return %intersection ?? min(%intersection.keys).Int !! -1; +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 3; + + is minimum-common([1, 2, 3, 4], [3, 4, 5, 6]), 3, + 'works for "[1, 2, 3, 4], [3, 4, 5, 6]"'; + is minimum-common([1, 2, 3], [2, 4]), 2, 'works for "[1, 2, 3], [2, 4]"'; + is minimum-common([1, 2, 3, 4], [5, 6, 7, 8]), -1, + 'works for "[1, 2, 3, 4], [5, 6, 7, 8]"'; +} |
