From ae590042b5bbc9a8542d849baf29672cd665ccbe Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Tue, 7 Jan 2025 17:25:05 +0000 Subject: [PATCH] pass graph as last arg --- day-14/internal/one/solve.go | 10 +++++----- day-14/internal/two/solve.go | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/day-14/internal/one/solve.go b/day-14/internal/one/solve.go index 93d8d69..e34c7cf 100644 --- a/day-14/internal/one/solve.go +++ b/day-14/internal/one/solve.go @@ -31,11 +31,11 @@ func Solve(buf []byte) (int, error) { return safetyFactor, nil } -func calculateQuadrants(graph *graph) []int { - topLeft := graph.quadrant(0, len(graph.data[0])/2, 0, len(graph.data)/2) - topRight := graph.quadrant(len(graph.data[0])/2+1, len(graph.data[0]), 0, len(graph.data)/2) - bottomLeft := graph.quadrant(0, len(graph.data[0])/2, len(graph.data)/2+1, len(graph.data)) - bottomRight := graph.quadrant(len(graph.data[0])/2+1, len(graph.data[0]), len(graph.data)/2+1, len(graph.data)) +func calculateQuadrants(g *graph) []int { + topLeft := g.quadrant(0, len(g.data[0])/2, 0, len(g.data)/2) + topRight := g.quadrant(len(g.data[0])/2+1, len(g.data[0]), 0, len(g.data)/2) + bottomLeft := g.quadrant(0, len(g.data[0])/2, len(g.data)/2+1, len(g.data)) + bottomRight := g.quadrant(len(g.data[0])/2+1, len(g.data[0]), len(g.data)/2+1, len(g.data)) return []int{topLeft, topRight, bottomLeft, bottomRight} } diff --git a/day-14/internal/two/solve.go b/day-14/internal/two/solve.go index 5ddf19b..88caa7b 100644 --- a/day-14/internal/two/solve.go +++ b/day-14/internal/two/solve.go @@ -24,7 +24,7 @@ func Solve(buf []byte) (int, error) { } graph.update(robots) - numNeighbours := evaluateNeighbours(graph, robots) + numNeighbours := evaluateNeighbours(robots, graph) if numNeighbours > max { max = numNeighbours maxAtSecond = i @@ -34,15 +34,15 @@ func Solve(buf []byte) (int, error) { return maxAtSecond, nil } -func evaluateNeighbours(graph *graph, robots []*robot) int { +func evaluateNeighbours(robots []*robot, g *graph) int { var numNeighbours int for _, robot := range robots { for _, n := range neighbours(robot.position) { - if graph.isOutOfBounds(n) { + if g.isOutOfBounds(n) { continue } - if graph.valueAt(n) > 0 { + if g.valueAt(n) > 0 { numNeighbours++ } }