package one import ( "slices" "strings" "github.com/onyx-and-iris/aoc2024/day-18/internal/point" orderedmap "github.com/wk8/go-ordered-map/v2" ) type graph struct { start point.Point end point.Point data []string } func newGraph(width, height, numCorruptions int, corruptedCoords [][]int) *graph { var data []string var sb strings.Builder for range height { for range width { sb.WriteRune('.') } data = append(data, sb.String()) sb.Reset() } for _, coords := range corruptedCoords[:numCorruptions] { data[coords[1]] = replaceAtIndex(data[coords[1]], '#', coords[0]) } return &graph{point.Point{X: 0, Y: 0}, point.Point{X: len(data[0]) - 1, Y: len(data) - 1}, data} } func (g *graph) String() string { return strings.Join(g.data, "\n") } func (g *graph) isOutOfBounds(p point.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.Point) rune { return rune(g.data[p.Y][p.X]) } func (g *graph) debug(path *orderedmap.OrderedMap[point.Point, struct{}]) string { temp := slices.Clone(g.data) temp[g.start.Y] = replaceAtIndex(temp[g.start.Y], 'O', g.start.X) for pair := path.Oldest(); pair != nil; pair = pair.Next() { temp[pair.Key.Y] = replaceAtIndex(temp[pair.Key.Y], 'O', pair.Key.X) } return strings.Join(temp, "\n") }