Skip to content

Commit

Permalink
Add solution for day 3
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikSchnack committed Dec 3, 2024
1 parent fb5c0b2 commit 40f94b2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion inputs
2 changes: 1 addition & 1 deletion solutions/2024/src/AdventOfCode24.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module AdventOfCode24
readInput(day::Int) = AdventOfCode.readInput(day, year)
export readInput

solvedDays = [1]
solvedDays = [1, 2, 3]

# Include the source files:
for day in solvedDays
Expand Down
39 changes: 39 additions & 0 deletions solutions/2024/src/day03.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Day03
using ..AdventOfCode24

"""
day03()
Solves the two puzzles of day 03.
"""

function day03(input::String = readInput(03))

s0 = mul(input)
s1 = 0

for l in split(input, "do()")

i = findfirst("don't()", l)
!isnothing(i) && (l = first(l, first(i)))

s1 += mul(l)
end

return [s0, s1]
end

function mul(ops::AbstractString)
r = r"mul\((\d+),(\d+)\)"
s = 0
for m in eachmatch(r, ops)
a = parse(Int, m.captures[1])
b = parse(Int, m.captures[2])
s += a*b
end

return s
end

end

4 changes: 4 additions & 0 deletions solutions/2024/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ end
@test AdventOfCode24.Day02.day02() == [356 , 413]
end

@testset "Day 03" begin
@test AdventOfCode24.Day03.day03() == [162813399 , 53783319]
end

0 comments on commit 40f94b2

Please sign in to comment.