aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarrOff <58253563+BarrOff@users.noreply.github.com>2025-08-31 22:58:57 +0200
committerBarrOff <58253563+BarrOff@users.noreply.github.com>2025-08-31 22:58:57 +0200
commitbb14adb9b561d1ab06bd1f6e3e2fb016256eb2b7 (patch)
tree6f1e6da3e13c299728fe3917910389757a0a7468
parent61cdfcd262b66ccfdc6e4be3b0723f48243cb92b (diff)
downloadperlweeklychallenge-club-bb14adb9b561d1ab06bd1f6e3e2fb016256eb2b7.tar.gz
perlweeklychallenge-club-bb14adb9b561d1ab06bd1f6e3e2fb016256eb2b7.tar.bz2
perlweeklychallenge-club-bb14adb9b561d1ab06bd1f6e3e2fb016256eb2b7.zip
feat: add solution for challenge 335 from BarrOff
-rw-r--r--challenge-335/barroff/raku/ch-1.p629
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-335/barroff/raku/ch-1.p6 b/challenge-335/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..ce7b6486ba
--- /dev/null
+++ b/challenge-335/barroff/raku/ch-1.p6
@@ -0,0 +1,29 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub common-characters(@words --> Seq) {
+ (reduce { $^a ∩ $^b }, @words.map({ $_.comb.Bag })).kxxv
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 5;
+
+ is common-characters(["bella", "label", "roller"]).sort, ["e", "l", "l"],
+ 'works for "bella", "label", "roller"';
+ is common-characters(["cool", "lock", "cook"]).sort, ["c", "o"],
+ 'works for "cool", "lock", "cook"';
+ is common-characters(["hello", "world", "pole"]).sort, ["l", "o"],
+ 'works for "hello", "world", "pole"';
+ is common-characters(["abc", "def", "ghi"]).sort, [],
+ 'works for "abc", "def", "ghi"';
+ is common-characters(["aab", "aac", "aaa"]).sort, ["a", "a"],
+ 'works for "aab", "aac", "aaa"';
+}
+
+#| Take user provided words like Perl Weekly Challenge
+multi sub MAIN(*@words) {
+ say common-characters(@words);
+}