package one type dimension int type graph struct { data [][]int } func newGraph(x, y dimension) *graph { var data [][]int for range y { data = append(data, make([]int, x)) } return &graph{data: data} } func (g *graph) update(robots []*robot) { for _, robot := range robots { g.updateEach(robot.position) } } func (g *graph) updateEach(p position) { g.data[p.y][p.x]++ } func (g *graph) quadrant(startx, endx, starty, endy int) int { var robotCount int for i := starty; i < endy; i++ { for j := startx; j < endx; j++ { robotCount += g.data[i][j] } } return robotCount }