mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
36 lines
590 B
Go
36 lines
590 B
Go
|
package two
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
|
||
|
"github.com/onyx-and-iris/aoc2024/day-06/internal/util"
|
||
|
)
|
||
|
|
||
|
type graph struct {
|
||
|
data []string
|
||
|
startPoint point
|
||
|
obstacles []point
|
||
|
}
|
||
|
|
||
|
func newGraph() *graph {
|
||
|
return &graph{}
|
||
|
}
|
||
|
|
||
|
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()
|
||
|
}
|