2024-12-08 19:55:23 +00:00
|
|
|
package one
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type graph struct {
|
|
|
|
data []string
|
|
|
|
antennae []antenna
|
|
|
|
antinodes map[coords]struct{}
|
|
|
|
}
|
|
|
|
|
2024-12-08 20:11:03 +00:00
|
|
|
func newGraph() *graph {
|
|
|
|
return &graph{antinodes: make(map[coords]struct{})}
|
|
|
|
}
|
|
|
|
|
2024-12-08 19:55:23 +00:00
|
|
|
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 {
|
2025-01-07 17:24:01 +00:00
|
|
|
g.data[antenna.y] = replaceAtIndex(g.data[antenna.y], antenna.identifier, antenna.x)
|
2024-12-08 19:55:23 +00:00
|
|
|
}
|
|
|
|
for antinode := range g.antinodes {
|
2025-01-07 17:24:01 +00:00
|
|
|
g.data[antinode.y] = replaceAtIndex(g.data[antinode.y], '#', antinode.x)
|
2024-12-08 19:55:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return g.String()
|
|
|
|
}
|