aoc2024/day-10/internal/one/graph.go

41 lines
724 B
Go
Raw Normal View History

2024-12-10 21:45:16 +00:00
package one
import (
"slices"
"strings"
)
type point struct {
x int
y int
}
type graph struct {
data []string
startPositions []point
}
func newGrid() *graph {
return &graph{data: make([]string, 0), startPositions: make([]point, 0)}
}
func (g *graph) String() string {
return strings.Join(g.data, "\n")
}
func (g *graph) isOutOfBounds(p point) bool {
return p.x < 0 || p.y < 0 || p.y >= len(g.data) || p.x >= len(g.data[p.y])
}
func (g *graph) valueAt(p point) rune {
return rune(g.data[p.y][p.x])
}
func (g *graph) debug(path []point) string {
temp := slices.Clone(g.data)
for _, pos := range path {
temp[pos.y] = replaceAtIndex(temp[pos.y], '+', pos.x)
}
return strings.Join(temp, "\n")
}