-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb5c0b2
commit 40f94b2
Showing
4 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
Submodule inputs
updated
from 2c9945 to a47e3a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters