mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 06:10:47 +00:00
35 lines
698 B
Go
35 lines
698 B
Go
package two
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
type graph struct {
|
|
data []string
|
|
antennae []antenna
|
|
antinodes antiNodeCache
|
|
}
|
|
|
|
func newGraph() *graph {
|
|
return &graph{antinodes: newAntiNodeCache()}
|
|
}
|
|
|
|
func (g *graph) String() string {
|
|
return strings.Join(g.data, "\n")
|
|
}
|
|
|
|
func (g *graph) isOutOfBounds(c coords) bool {
|
|
return c.x < 0 || c.y < 0 || c.y >= len(g.data) || c.x >= len(g.data[0])
|
|
}
|
|
|
|
func (g *graph) debug() string {
|
|
for _, antenna := range g.antennae {
|
|
g.data[antenna.y] = replaceAtIndex(g.data[antenna.y], antenna.identifier, antenna.x)
|
|
}
|
|
for antinode := range g.antinodes.data {
|
|
g.data[antinode.y] = replaceAtIndex(g.data[antinode.y], '#', antinode.x)
|
|
}
|
|
|
|
return g.String()
|
|
}
|