aoc2024/day-20/internal/two/graph.go

39 lines
704 B
Go
Raw Permalink Normal View History

2024-12-20 20:48:13 +00:00
package two
import (
"slices"
"strings"
"github.com/onyx-and-iris/aoc2024/day-20/internal/point"
"github.com/elliotchance/orderedmap/v3"
)
type graph struct {
start, end point.Point
data []string
}
func newGraph(data []string) *graph {
return &graph{data: data}
}
func (g *graph) String() string {
return strings.Join(g.data, "\n")
}
func (g *graph) valueAt(p point.Point) rune {
return rune(g.data[p.Y][p.X])
}
func (g *graph) debug(path *orderedmap.OrderedMap[point.Point, int]) string {
temp := slices.Clone(g.data)
for n := range path.Keys() {
if g.valueAt(n) == 'X' {
continue
}
temp[n.Y] = replaceAtIndex(temp[n.Y], 'O', n.X)
}
return strings.Join(temp, "\n")
}