2024-12-06 20:01:17 +00:00
|
|
|
package two
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/onyx-and-iris/aoc2024/day-06/internal/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
type graph struct {
|
|
|
|
startPoint point
|
2024-12-06 22:23:01 +00:00
|
|
|
data []string
|
2024-12-06 20:01:17 +00:00
|
|
|
}
|
|
|
|
|
2024-12-06 22:23:01 +00:00
|
|
|
func newGraph(startPoint point, data []string) *graph {
|
|
|
|
return &graph{startPoint: startPoint, data: data}
|
2024-12-06 20:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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] = util.ReplaceAtIndex(g.data[loc.y], '+', loc.x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return g.String()
|
|
|
|
}
|