diff options
| author | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-08-04 22:59:08 +0200 |
|---|---|---|
| committer | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-08-04 22:59:08 +0200 |
| commit | 3363a2e7f121eeab5712e83801137295fbb4be16 (patch) | |
| tree | 45e3cd8a267c90ce3d4924321aff220ce3a7a772 /challenge-280/barroff/julia | |
| parent | 319fa5ea206dcaab749b20d0a8578479fb894d3c (diff) | |
| download | perlweeklychallenge-club-3363a2e7f121eeab5712e83801137295fbb4be16.tar.gz perlweeklychallenge-club-3363a2e7f121eeab5712e83801137295fbb4be16.tar.bz2 perlweeklychallenge-club-3363a2e7f121eeab5712e83801137295fbb4be16.zip | |
feat: add solutions for challenge 280 from BarrOff
Diffstat (limited to 'challenge-280/barroff/julia')
| -rw-r--r-- | challenge-280/barroff/julia/ch-1.jl | 19 | ||||
| -rw-r--r-- | challenge-280/barroff/julia/ch-2.jl | 14 |
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-280/barroff/julia/ch-1.jl b/challenge-280/barroff/julia/ch-1.jl new file mode 100644 index 0000000000..056e092cc3 --- /dev/null +++ b/challenge-280/barroff/julia/ch-1.jl @@ -0,0 +1,19 @@ +#!/usr/bin/env julia + +using Test: @test, @testset + +function twice_appearance(str::AbstractString)::Char + str_set = Set{Char}() + for c in str + if in(c, str_set) + return c + end + push!(str_set, c) + end +end + +@testset "twice appearance" begin + @test twice_appearance("acbddbca") == 'd' + @test twice_appearance("abccd") == 'c' + @test twice_appearance("abcdabbb") == 'a' +end diff --git a/challenge-280/barroff/julia/ch-2.jl b/challenge-280/barroff/julia/ch-2.jl new file mode 100644 index 0000000000..f1115fdc28 --- /dev/null +++ b/challenge-280/barroff/julia/ch-2.jl @@ -0,0 +1,14 @@ +#!/usr/bin/env julia + +using Test: @test, @testset + +function count_asterisks(str::AbstractString)::Int + pairless = replace(str, r"\|.*?\|" => "") + count(x -> x == '*', pairless) +end + +@testset "count asterisks" begin + @test count_asterisks("p|*e*rl|w**e|*ekly|") == 2 + @test count_asterisks("perl") == 0 + @test count_asterisks("th|ewe|e**|k|l***ych|alleng|e") == 5 +end |
