diff --git a/day-16/internal/one/solve.go b/day-16/internal/one/solve.go index ab20204..726971d 100644 --- a/day-16/internal/one/solve.go +++ b/day-16/internal/one/solve.go @@ -4,6 +4,8 @@ import ( "bytes" ) +var LowestCost int + func Solve(buf []byte) (int, error) { r := bytes.NewReader(buf) graph, err := parseLines(r) @@ -11,10 +13,10 @@ func Solve(buf []byte) (int, error) { return 0, err } - lowestCost, err := graph.dijkstra() + LowestCost, err = graph.dijkstra() if err != nil { return 0, err } - return lowestCost, nil + return LowestCost, nil } diff --git a/day-16/internal/two/graph.go b/day-16/internal/two/graph.go index 30519e2..346e57e 100644 --- a/day-16/internal/two/graph.go +++ b/day-16/internal/two/graph.go @@ -2,10 +2,10 @@ package two import ( hp "container/heap" - "math" "slices" "strings" + "github.com/onyx-and-iris/aoc2024/day-16/internal/one" log "github.com/sirupsen/logrus" ) @@ -32,20 +32,18 @@ func (g *graph) dijkstra() int { hp.Push(heap, move{g.start, 0, []node{g.start}}) visited := make(map[node]int) const turnCost int = 1000 - lowestCost := math.MaxInt - bestPaths := [][]node{} + lowestCostPaths := [][]node{} for heap.Len() > 0 { current := hp.Pop(heap).(move) // we're on a path that's already exceeded the lowest cost - if current.cost > lowestCost { + if current.cost > one.LowestCost { continue } if g.valueAt(current.node) == 'E' { - bestPaths = append(bestPaths, current.path) - lowestCost = current.cost + lowestCostPaths = append(lowestCostPaths, current.path) continue } @@ -71,7 +69,7 @@ func (g *graph) dijkstra() int { } possibleSafe := make(map[coords]struct{}) - for _, path := range bestPaths { + for _, path := range lowestCostPaths { for _, n := range path { possibleSafe[n.coords] = struct{}{} }