diff options
| author | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-06-30 21:25:29 +0200 |
|---|---|---|
| committer | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-06-30 21:25:29 +0200 |
| commit | a0c6a40db5e0454b3436d4ef3d98658cbfbd8709 (patch) | |
| tree | 9f85d688b0b65090c2db0da5f329d36310979c62 | |
| parent | eacf83221547213b01db7a74b846ee18dd83db5a (diff) | |
| download | perlweeklychallenge-club-a0c6a40db5e0454b3436d4ef3d98658cbfbd8709.tar.gz perlweeklychallenge-club-a0c6a40db5e0454b3436d4ef3d98658cbfbd8709.tar.bz2 perlweeklychallenge-club-a0c6a40db5e0454b3436d4ef3d98658cbfbd8709.zip | |
feat: add solutions for challenge 275 from BarrOff
| -rw-r--r-- | challenge-275/barroff/julia/ch-1.jl | 20 | ||||
| -rw-r--r-- | challenge-275/barroff/raku/ch-1.p6 | 27 |
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); +} |
