aboutsummaryrefslogtreecommitdiff
path: root/challenge-307/barroff/julia
diff options
context:
space:
mode:
authorBarrOff <58253563+BarrOff@users.noreply.github.com>2025-02-10 07:40:30 +0100
committerBarrOff <58253563+BarrOff@users.noreply.github.com>2025-02-10 07:40:30 +0100
commit53f6116a8421948cc1e76fda4c1da3437a87b129 (patch)
treefa75a297618bb5c87a75ad4c39de4b4c960326b3 /challenge-307/barroff/julia
parentaa4b8399bdb3da0a50173fcab689bfa80b9b54e1 (diff)
downloadperlweeklychallenge-club-53f6116a8421948cc1e76fda4c1da3437a87b129.tar.gz
perlweeklychallenge-club-53f6116a8421948cc1e76fda4c1da3437a87b129.tar.bz2
perlweeklychallenge-club-53f6116a8421948cc1e76fda4c1da3437a87b129.zip
feat: add solutions for challenge 307 from BarrOff
Diffstat (limited to 'challenge-307/barroff/julia')
-rw-r--r--challenge-307/barroff/julia/ch-1.jl14
-rw-r--r--challenge-307/barroff/julia/ch-2.jl13
2 files changed, 27 insertions, 0 deletions
diff --git a/challenge-307/barroff/julia/ch-1.jl b/challenge-307/barroff/julia/ch-1.jl
new file mode 100644
index 0000000000..742a9c304b
--- /dev/null
+++ b/challenge-307/barroff/julia/ch-1.jl
@@ -0,0 +1,14 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function checkOrder(ints::Vector{Int})::Vector{Int}
+ sortedInts = sort(ints)
+ return filter(x -> ints[x] != sortedInts[x], 1:length(ints)) .- 1
+end
+
+@testset "check order" begin
+ @test checkOrder([5, 2, 4, 3, 1]) == [0, 2, 3, 4]
+ @test checkOrder([1, 2, 1, 1, 3]) == [1, 3]
+ @test checkOrder([3, 1, 3, 2, 3]) == [0, 1, 3]
+end
diff --git a/challenge-307/barroff/julia/ch-2.jl b/challenge-307/barroff/julia/ch-2.jl
new file mode 100644
index 0000000000..04794007ad
--- /dev/null
+++ b/challenge-307/barroff/julia/ch-2.jl
@@ -0,0 +1,13 @@
+#!/usr/bin/env julia
+
+using Test: @test, @testset
+
+function find_anagrams(words::Vector{String})::Int
+ cleanedWords = [join(sort(collect(x))) for x in words]
+ return count(x -> cleanedWords[x] != cleanedWords[x+1], 1:length(words)-1) + 1
+end
+
+@testset "find anagrams" begin
+ @test find_anagrams(["acca", "dog", "god", "perl", "repl"]) == 3
+ @test find_anagrams(["abba", "baba", "aabb", "ab", "ab"]) == 2
+end