aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-275/barroff/julia/ch-1.jl20
-rw-r--r--challenge-275/barroff/raku/ch-1.p627
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-275/barroff/julia/ch-1.jl b/challenge-275/barroff/julia/ch-1.jl
new file mode 100644
index 0000000000..7a29d8657f
--- /dev/null
+++ b/challenge-275/barroff/julia/ch-1.jl
@@ -0,0 +1,20 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function broken_keys(str::AbstractString, keys::Vector{Char})::Int
+ keys_set = Set(map(x -> lowercase(string(x)), keys))
+ length(
+ filter(
+ x -> isempty(intersect(Set(split(lowercase(x), "")), keys_set)),
+ split(str)
+ )
+ )
+end
+
+@testset "broken keys" begin
+ @test broken_keys("Perl Weekly Challenge", ['l', 'a']) == 0
+ @test broken_keys("Perl and Raku", ['a']) == 1
+ @test broken_keys("Well done Team PWC", ['l', 'o']) == 2
+ @test broken_keys("The joys of polyglottism", ['T']) == 2
+end
diff --git a/challenge-275/barroff/raku/ch-1.p6 b/challenge-275/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..6a6ec163fa
--- /dev/null
+++ b/challenge-275/barroff/raku/ch-1.p6
@@ -0,0 +1,27 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub broken-keys(Str $sentence, @keys --> Int) {
+ my $key-set = Set(map(&lc,@keys));
+ grep({ $key-set (&) Set($_.comb) == ∅ }, $sentence.lc.words).elems;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 4;
+
+ is broken-keys("Perl Weekly Challenge", ['l', 'a']), 0,
+ 'works for "Perl Weekly Challenge"';
+ is broken-keys("Perl and Raku", ['a']), 1, 'works for "Perl and Raku"';
+ is broken-keys("Well done Team PWC", ['l', 'o']), 2,
+ 'works for "Well done Team PWC"';
+ is broken-keys("The joys of polyglottism", ['T']), 2,
+ 'works for "The joys of polyglottism"';
+}
+
+#| Take user provided number like "Perl Weekly Challenge" l a
+multi sub MAIN(Str $sentence, *@keys) {
+ say broken-keys($sentence, @keys);
+}