mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
42 lines
755 B
Go
42 lines
755 B
Go
package two
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
)
|
|
|
|
type point struct {
|
|
x int
|
|
y int
|
|
direction 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")
|
|
}
|