aboutsummaryrefslogtreecommitdiff
path: root/challenge-234/barroff/julia
diff options
context:
space:
mode:
authorBarrOff <58253563+BarrOff@users.noreply.github.com>2023-09-17 23:21:22 +0200
committerBarrOff <58253563+BarrOff@users.noreply.github.com>2023-09-17 23:21:22 +0200
commit85b5521e55a233585a5c4ea830921e70169f6a59 (patch)
treee9fee75f8a463b65607984d0cd3f65d636a33437 /challenge-234/barroff/julia
parent3f85224aa3a84d4fb99755152cba5176cf49b795 (diff)
downloadperlweeklychallenge-club-85b5521e55a233585a5c4ea830921e70169f6a59.tar.gz
perlweeklychallenge-club-85b5521e55a233585a5c4ea830921e70169f6a59.tar.bz2
perlweeklychallenge-club-85b5521e55a233585a5c4ea830921e70169f6a59.zip
feat: add solutions for challenge 234 from BarrOff
Diffstat (limited to 'challenge-234/barroff/julia')
-rw-r--r--challenge-234/barroff/julia/ch-1.jl20
-rw-r--r--challenge-234/barroff/julia/ch-2.jl29
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-234/barroff/julia/ch-1.jl b/challenge-234/barroff/julia/ch-1.jl
new file mode 100644
index 0000000000..ccec86bfe6
--- /dev/null
+++ b/challenge-234/barroff/julia/ch-1.jl
@@ -0,0 +1,20 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function common_characters(words)
+ splitted_words = map(x -> split(x, ""), words)
+ characer_sets = map(x -> Set(x), splitted_words)
+ common_chars = reduce(intersect, characer_sets)
+ result = ""
+ for i in common_chars
+ result *= i ^ minimum(map(x -> count(y -> y == i, x), splitted_words))
+ end
+ return split(result, "")
+end
+
+@testset "common characters" begin
+ @test common_characters(["java", "javascript", "julia"]) == ["j", "a"]
+ @test common_characters(["bella", "label", "roller"]) == ["e", "l", "l"]
+ @test common_characters(["cool", "lock", "cook"]) == ["c", "o"]
+end
diff --git a/challenge-234/barroff/julia/ch-2.jl b/challenge-234/barroff/julia/ch-2.jl
new file mode 100644
index 0000000000..40a75decf6
--- /dev/null
+++ b/challenge-234/barroff/julia/ch-2.jl
@@ -0,0 +1,29 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function is_unequal(a, b, c)
+ if a != b && a != c && b != c
+ # println("$(a), $(b), $(c)")
+ return 1
+ end
+ return 0
+end
+
+function unequal_triplets(ints)
+ result = 0
+ for i in 1:length(ints) - 2
+ for j in i:length(ints) - 1
+ for k in j:length(ints)
+ result += is_unequal(ints[i], ints[j], ints[k])
+ end
+ end
+ end
+ return result
+end
+
+@testset "unequal triplets" begin
+ @test unequal_triplets([4, 4, 2, 4, 3]) == 3
+ @test unequal_triplets([1, 1, 1, 1, 1]) == 0
+ @test unequal_triplets([4, 7, 1, 10, 7, 4, 1, 1]) == 28
+end