advent_of_code_2022

My (attempted) solutions to the 2022 Advent of Code
git clone https://git.eamoncaddigan.net/advent_of_code_2022.git
Log | Files | Refs | README

commit 09fc897885233cca0455911979cb1e31ef19731f
parent 3afc67b9cb99a79240f14d4247eed371dbf47025
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date:   Thu, 15 Dec 2022 20:53:23 -0800

Solution to day 12, part 2.

Diffstat:
Msrc/day_12.jl | 10+++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/day_12.jl b/src/day_12.jl @@ -68,6 +68,11 @@ function pathdist(g::AbstractGraph, v_source::CartesianIndex{2}, pathdist(g, source_ind, dest_ind) end +function pathdist(g::AbstractGraph, v_source::Vector{CartesianIndex{2}}, + v_dest::CartesianIndex{2}, heightmap::AbstractMatrix) + map(x->pathdist(g, x, v_dest, heightmap), v_source) +end + function part_1(input) heightmap, v_source, v_dest = parse_input(input) pathdist(makegraph(heightmap), v_source, v_dest, heightmap) @@ -76,6 +81,9 @@ end @info part_1(input) function part_2(input) - nothing + heightmap, _, v_dest = parse_input(input) + v_source = findall(heightmap .== 0) + minimum(pathdist(makegraph(heightmap), v_source, v_dest, heightmap)) end +@assert part_2(example) == 29 @info part_2(input)