diff --git a/posts/adventofcode2024w2.md b/posts/adventofcode2024w2.md index c22f820..71af050 100644 --- a/posts/adventofcode2024w2.md +++ b/posts/adventofcode2024w2.md @@ -151,6 +151,36 @@ println(sum(pathsp1)) print(sum(pathsp2)) ``` +## Day 13 + +Pretty clean solution for Day 13. Don't love the round/asinteger solution but floating point problems were causing headaches. + +```julia +inst = readlines("data/13.txt") + +A = [parse.(Int, m.captures) for m in + match.(r"A: X\+(\d+), Y\+(\d+)", inst) if !isnothing(m)] +B = [parse.(Int, m.captures) for m in + match.(r"B: X\+(\d+), Y\+(\d+)", inst) if !isnothing(m)] +P = [parse.(Int, m.captures) for m in + match.(r"Prize: X\=(\d+), Y\=(\d+)", inst) if !isnothing(m)] + +function solve(adjust=0) + ans = 0 + for i in eachindex(A) + sol = hcat(A[i], B[i]) \ (P[i] .+ adjust) + if all(isinteger.(round.(sol, digits=3))) + ans += sum((3, 1) .* sol) + end + end + return ans +end + +println(solve()) +println(solve(10000000000000)) +``` + + ## Day 14 Solution to part one runs fast, clean solution. Part two requires you to watch a nearly 17 minute long video generated by Makie.jl to find the tree. I'm sure there was a smart way to do this, but when in doubt, look at the data...