mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 06:40:47 +00:00
37 lines
599 B
Go
37 lines
599 B
Go
|
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
|
||
|
}
|