diff options
| author | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2023-10-22 22:33:07 +0200 |
|---|---|---|
| committer | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2023-10-22 22:33:07 +0200 |
| commit | 8bef0d25ef6b7e2b915b3b66def3ced1412b2d4d (patch) | |
| tree | ef5de1de9fb65d5d62766a1506edb5e8ea9cde05 /challenge-239/barroff/julia | |
| parent | a1835fd1a935b02d48de48ef8242136522a540b4 (diff) | |
| download | perlweeklychallenge-club-8bef0d25ef6b7e2b915b3b66def3ced1412b2d4d.tar.gz perlweeklychallenge-club-8bef0d25ef6b7e2b915b3b66def3ced1412b2d4d.tar.bz2 perlweeklychallenge-club-8bef0d25ef6b7e2b915b3b66def3ced1412b2d4d.zip | |
feat: add solutions for challenge 239 from BarrOff
Diffstat (limited to 'challenge-239/barroff/julia')
| -rw-r--r-- | challenge-239/barroff/julia/ch-1.jl | 13 | ||||
| -rw-r--r-- | challenge-239/barroff/julia/ch-2.jl | 16 |
2 files changed, 29 insertions, 0 deletions
diff --git a/challenge-239/barroff/julia/ch-1.jl b/challenge-239/barroff/julia/ch-1.jl new file mode 100644 index 0000000000..b2ae66f1fc --- /dev/null +++ b/challenge-239/barroff/julia/ch-1.jl @@ -0,0 +1,13 @@ +#!/usr/bin/env julia + +using Test: @test, @testset + +function same_string(arr1::Vector{String}, arr2::Vector{String}) + return join(arr1, "") == join(arr2, "") +end + +@testset "same string" begin + @test same_string(["ab", "c"], ["a", "bc"]) == true + @test same_string(["ab", "c"], ["ac", "b"]) == false + @test same_string(["ab", "cd", "e"], ["abcde"]) == true +end diff --git a/challenge-239/barroff/julia/ch-2.jl b/challenge-239/barroff/julia/ch-2.jl new file mode 100644 index 0000000000..f9890127ec --- /dev/null +++ b/challenge-239/barroff/julia/ch-2.jl @@ -0,0 +1,16 @@ +#!/usr/bin/env julia + +using Test: @test, @testset + +function consistent_strings(allowed::String, words::Vector{String}) + splitted_words = map(x -> split(x, ""), words) + characer_sets = map(x -> Set(x), splitted_words) + allowed_chars = Set(split(allowed, "")) + return length(filter(x -> x ⊆ allowed_chars, characer_sets)) +end + +@testset "consistent strings" begin + @test consistent_strings("ab", ["ad", "bd", "aaab", "baa", "badab"]) == 2 + @test consistent_strings("abc", ["a", "b", "c", "ab", "ac", "bc", "abc"]) == 7 + @test consistent_strings("cad", ["cc", "acd", "b", "ba", "bac", "bad", "ac", "d"]) == 4 +end |
