diff options
| author | Scimon <simon.proctor@gmail.com> | 2025-08-18 09:42:02 +0100 |
|---|---|---|
| committer | Scimon <simon.proctor@gmail.com> | 2025-08-18 09:42:02 +0100 |
| commit | a3d438220113eae12749f3e9d49df17535efc96c (patch) | |
| tree | ff1baf9a4ff6af4f1e78acbfde30f57766f40020 | |
| parent | 4f766edf1327ad3628c824c3c00f1c1f10c50b38 (diff) | |
| download | perlweeklychallenge-club-a3d438220113eae12749f3e9d49df17535efc96c.tar.gz perlweeklychallenge-club-a3d438220113eae12749f3e9d49df17535efc96c.tar.bz2 perlweeklychallenge-club-a3d438220113eae12749f3e9d49df17535efc96c.zip | |
Challenge 1
| -rwxr-xr-x | challenge-335/simon-proctor/raku/ch-1.raku | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-335/simon-proctor/raku/ch-1.raku b/challenge-335/simon-proctor/raku/ch-1.raku new file mode 100755 index 0000000000..b9d51a2066 --- /dev/null +++ b/challenge-335/simon-proctor/raku/ch-1.raku @@ -0,0 +1,24 @@ +#!/usr/bin/env raku + +multi sub MAIN(:t(:$test)) is hidden-from-USAGE { + use Test; + is common-chars("bella", "label", "roller"), ("e", "l", "l"); + is common-chars("cool", "lock", "cook"), ("c", "o"); + is common-chars("hello", "world", "pole"), ("l", "o"); + is common-chars("abc", "def", "ghi"),(); + is common-chars("aab", "aac", "aaa"),("a", "a"); + done-testing; +} + +multi sub common-chars( *@words where all(@words) ~~ Str ) { + common-chars(@words); +} + +multi sub common-chars( @words where all(@words) ~~ Str ) { + return ( [(&)] @words.map( *.comb.Bag ) ).map( -> $p { |($p.key xx $p.value) } ).sort; +} + +#| Given a list of strings print an orders list of the common characters +multi sub MAIN( *@words where all(@words) ~~ Str ) { + common-chars(@words).join(",").say; +} |
