From 17dc9c083fafc62fdbe1df282c47b1c3bcbe46cf Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 4 Mar 2024 00:38:46 +0000 Subject: - Added solutions by Simon Green. - Added solutions by BarrOff. - Added solutions by Bruce Gray. - Added solutions by Matthias Muth. - Added solutions by Adam Russell. --- challenge-258/barroff/julia/ch-2.jl | 20 ++++++++++++++++++++ challenge-258/barroff/julia/ch_2.jl | 20 -------------------- 2 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 challenge-258/barroff/julia/ch-2.jl delete mode 100644 challenge-258/barroff/julia/ch_2.jl (limited to 'challenge-258') diff --git a/challenge-258/barroff/julia/ch-2.jl b/challenge-258/barroff/julia/ch-2.jl new file mode 100644 index 0000000000..e322ee3845 --- /dev/null +++ b/challenge-258/barroff/julia/ch-2.jl @@ -0,0 +1,20 @@ +#!/usr/bin/env julia + +using Test: @test, @testset + +function sum_of_values(ints::Vector{T}, k::T) where {T<:Integer} + sum( + ints[ + filter( + x -> count(y -> y == '1', string(x - 1, base=2)) == k, + 1:length(ints) + ) + ] + ) +end + +@testset "count even digits number" begin + @test sum_of_values([2, 5, 9, 11, 3], 1) == 17 + @test sum_of_values([2, 5, 9, 11, 3], 2) == 11 + @test sum_of_values([2, 5, 9, 11, 3], 0) == 2 +end diff --git a/challenge-258/barroff/julia/ch_2.jl b/challenge-258/barroff/julia/ch_2.jl deleted file mode 100644 index e322ee3845..0000000000 --- a/challenge-258/barroff/julia/ch_2.jl +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env julia - -using Test: @test, @testset - -function sum_of_values(ints::Vector{T}, k::T) where {T<:Integer} - sum( - ints[ - filter( - x -> count(y -> y == '1', string(x - 1, base=2)) == k, - 1:length(ints) - ) - ] - ) -end - -@testset "count even digits number" begin - @test sum_of_values([2, 5, 9, 11, 3], 1) == 17 - @test sum_of_values([2, 5, 9, 11, 3], 2) == 11 - @test sum_of_values([2, 5, 9, 11, 3], 0) == 2 -end -- cgit