diff options
| -rw-r--r-- | challenge-335/barroff/raku/ch-1.p6 | 29 |
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); +} |
