pass graph as last arg

This commit is contained in:
onyx-and-iris 2025-01-07 17:25:05 +00:00
parent 21e942c56d
commit ae590042b5
2 changed files with 9 additions and 9 deletions

View File

@ -31,11 +31,11 @@ func Solve(buf []byte) (int, error) {
return safetyFactor, nil return safetyFactor, nil
} }
func calculateQuadrants(graph *graph) []int { func calculateQuadrants(g *graph) []int {
topLeft := graph.quadrant(0, len(graph.data[0])/2, 0, len(graph.data)/2) topLeft := g.quadrant(0, len(g.data[0])/2, 0, len(g.data)/2)
topRight := graph.quadrant(len(graph.data[0])/2+1, len(graph.data[0]), 0, len(graph.data)/2) topRight := g.quadrant(len(g.data[0])/2+1, len(g.data[0]), 0, len(g.data)/2)
bottomLeft := graph.quadrant(0, len(graph.data[0])/2, len(graph.data)/2+1, len(graph.data)) bottomLeft := g.quadrant(0, len(g.data[0])/2, len(g.data)/2+1, len(g.data))
bottomRight := graph.quadrant(len(graph.data[0])/2+1, len(graph.data[0]), len(graph.data)/2+1, len(graph.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} return []int{topLeft, topRight, bottomLeft, bottomRight}
} }

View File

@ -24,7 +24,7 @@ func Solve(buf []byte) (int, error) {
} }
graph.update(robots) graph.update(robots)
numNeighbours := evaluateNeighbours(graph, robots) numNeighbours := evaluateNeighbours(robots, graph)
if numNeighbours > max { if numNeighbours > max {
max = numNeighbours max = numNeighbours
maxAtSecond = i maxAtSecond = i
@ -34,15 +34,15 @@ func Solve(buf []byte) (int, error) {
return maxAtSecond, nil return maxAtSecond, nil
} }
func evaluateNeighbours(graph *graph, robots []*robot) int { func evaluateNeighbours(robots []*robot, g *graph) int {
var numNeighbours int var numNeighbours int
for _, robot := range robots { for _, robot := range robots {
for _, n := range neighbours(robot.position) { for _, n := range neighbours(robot.position) {
if graph.isOutOfBounds(n) { if g.isOutOfBounds(n) {
continue continue
} }
if graph.valueAt(n) > 0 { if g.valueAt(n) > 0 {
numNeighbours++ numNeighbours++
} }
} }