aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScimon <simon.proctor@gmail.com>2025-08-18 09:42:02 +0100
committerScimon <simon.proctor@gmail.com>2025-08-18 09:42:02 +0100
commita3d438220113eae12749f3e9d49df17535efc96c (patch)
treeff1baf9a4ff6af4f1e78acbfde30f57766f40020
parent4f766edf1327ad3628c824c3c00f1c1f10c50b38 (diff)
downloadperlweeklychallenge-club-a3d438220113eae12749f3e9d49df17535efc96c.tar.gz
perlweeklychallenge-club-a3d438220113eae12749f3e9d49df17535efc96c.tar.bz2
perlweeklychallenge-club-a3d438220113eae12749f3e9d49df17535efc96c.zip
Challenge 1
-rwxr-xr-xchallenge-335/simon-proctor/raku/ch-1.raku24
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;
+}