package two import ( "bytes" ) func Solve(buf []byte) (int, error) { r := bytes.NewReader(buf) robots, err := parseLines(r) if err != nil { return 0, err } const maxSeconds int = 10e3 const width, height dimension = 101, 103 var graph *graph var max, maxAtSecond int for i := 1; i <= maxSeconds; i++ { graph = newGraph(width, height) for _, robot := range robots { robot.update(width, height) } graph.update(robots) numNeighbours := evaluateNeighbours(graph, robots) if numNeighbours > max { max = numNeighbours maxAtSecond = i } } return maxAtSecond, nil } func evaluateNeighbours(graph *graph, robots []*robot) int { var numNeighbours int for _, robot := range robots { for _, n := range neighbours(robot.position) { if graph.isOutOfBounds(n) { continue } if graph.valueAt(n) > 0 { numNeighbours++ } } } return numNeighbours }