mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 22:30:47 +00:00
33 lines
572 B
Go
33 lines
572 B
Go
package two
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
type graph struct {
|
|
startPoint point
|
|
data []string
|
|
}
|
|
|
|
func newGraph(startPoint point, data []string) *graph {
|
|
return &graph{startPoint: startPoint, data: data}
|
|
}
|
|
|
|
func (g *graph) String() string {
|
|
return strings.Join(g.data, "\n")
|
|
}
|
|
|
|
func (g *graph) valueAt(x, y int) rune {
|
|
return rune(g.data[y][x])
|
|
}
|
|
|
|
func (g *graph) trace(visited map[point]struct{}) string {
|
|
for loc := range visited {
|
|
if !(rune(g.data[loc.y][loc.x]) == 'O') {
|
|
g.data[loc.y] = replaceAtIndex(g.data[loc.y], '+', loc.x)
|
|
}
|
|
}
|
|
|
|
return g.String()
|
|
}
|