From c125230c9b8b759d99bf7fd57ed564d676bae6c8 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Tue, 7 Jan 2025 17:24:23 +0000 Subject: [PATCH] pass graph as last arg --- day-12/internal/two/solve.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/day-12/internal/two/solve.go b/day-12/internal/two/solve.go index 7e4628b..90e9772 100644 --- a/day-12/internal/two/solve.go +++ b/day-12/internal/two/solve.go @@ -29,7 +29,7 @@ func Solve(buf []byte) (int, error) { totalAreaVisited[start] = struct{}{} path := exploreAreaSequentially(start, graph) - numSides := analyzeSides(graph.valueAt(firstPointFromMap(path.visited)), graph, path) + numSides := analyzeSides(graph.valueAt(firstPointFromMap(path.visited)), path, graph) totalCost += len(path.visited) * numSides for point := range path.visited { @@ -47,8 +47,8 @@ const ( diagonal ) -func analyzeSides(kind rune, graph *graph, path path) int { - log.Debugf("graph for values %s\n%s\n", string(kind), graph.debug(path.visited)) +func analyzeSides(kind rune, path path, g *graph) int { + log.Debugf("graph for values %s\n%s\n", string(kind), g.debug(path.visited)) var corners int for current := range path.visited { @@ -60,11 +60,11 @@ func analyzeSides(kind rune, graph *graph, path path) int { {ns[S], ns[E], point{current.x + 1, current.y + 1}}, {ns[S], ns[W], point{current.x - 1, current.y + 1}}, } { - if isCorner(graph, current, points[first], points[second]) { + if isCorner(current, points[first], points[second], g) { corners++ } - if isInnerCorner(graph, current, points[first], points[second], points[diagonal]) { + if isInnerCorner(current, points[first], points[second], points[diagonal], g) { corners++ } } @@ -75,25 +75,25 @@ func analyzeSides(kind rune, graph *graph, path path) int { return corners } -func isCorner(graph *graph, current, p, q point) bool { - if graph.isOutOfBounds(p) && graph.isOutOfBounds(q) { +func isCorner(current, p, q point, g *graph) bool { + if g.isOutOfBounds(p) && g.isOutOfBounds(q) { return true } - if !graph.isOutOfBounds(p) { - if graph.isOutOfBounds(q) && !graph.sameKind(p, current) { + if !g.isOutOfBounds(p) { + if g.isOutOfBounds(q) && !g.sameKind(p, current) { return true } } - if !graph.isOutOfBounds(q) { - if graph.isOutOfBounds(p) && !graph.sameKind(q, current) { + if !g.isOutOfBounds(q) { + if g.isOutOfBounds(p) && !g.sameKind(q, current) { return true } } - if !graph.isOutOfBounds(p) && !graph.isOutOfBounds(q) { - if !graph.sameKind(p, current) && !graph.sameKind(q, current) { + if !g.isOutOfBounds(p) && !g.isOutOfBounds(q) { + if !g.sameKind(p, current) && !g.sameKind(q, current) { return true } } @@ -101,10 +101,10 @@ func isCorner(graph *graph, current, p, q point) bool { return false } -func isInnerCorner(graph *graph, current, p, q, diagonal point) bool { - if !graph.isOutOfBounds(p) && !graph.isOutOfBounds(q) { - if graph.sameKind(p, current) && graph.sameKind(q, current) && - !graph.sameKind(diagonal, current) { +func isInnerCorner(current, p, q, diagonal point, g *graph) bool { + if !g.isOutOfBounds(p) && !g.isOutOfBounds(q) { + if g.sameKind(p, current) && g.sameKind(q, current) && + !g.sameKind(diagonal, current) { return true } }