diff --git a/day-10/internal/two/graph.go b/day-10/internal/two/graph.go index 2ce384b..0adcc98 100644 --- a/day-10/internal/two/graph.go +++ b/day-10/internal/two/graph.go @@ -1,14 +1,12 @@ package two import ( - "slices" "strings" ) type point struct { - x int - y int - direction int + x int + y int } type graph struct { @@ -31,11 +29,3 @@ func (g *graph) isOutOfBounds(p point) bool { 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") -} diff --git a/day-10/internal/two/neighbours.go b/day-10/internal/two/neighbours.go index 70c6e01..6a59d28 100644 --- a/day-10/internal/two/neighbours.go +++ b/day-10/internal/two/neighbours.go @@ -2,9 +2,9 @@ package two func neighbours(p point) [4]point { return [4]point{ - {p.x, p.y - 1, N}, - {p.x + 1, p.y, E}, - {p.x, p.y + 1, S}, - {p.x - 1, p.y, W}, + {p.x, p.y - 1}, + {p.x + 1, p.y}, + {p.x, p.y + 1}, + {p.x - 1, p.y}, } } diff --git a/day-10/internal/two/solve.go b/day-10/internal/two/solve.go index 28e6416..17a92fd 100644 --- a/day-10/internal/two/solve.go +++ b/day-10/internal/two/solve.go @@ -34,15 +34,11 @@ func Solve(buf []byte) (int, error) { continue } - for dir, n := range neighbours(current) { + for _, n := range neighbours(current) { if graph.isOutOfBounds(n) { continue } - if n.direction == None { - n.direction = dir - } - if graph.valueAt(n)-graph.valueAt(current) == 1 { log.Tracef("pushing %v with value %s back onto the queue\n", n, string(graph.valueAt(n))) queue.Enqueue(n) diff --git a/day-10/internal/two/util.go b/day-10/internal/two/util.go index ecf5ab6..bbde13f 100644 --- a/day-10/internal/two/util.go +++ b/day-10/internal/two/util.go @@ -22,7 +22,7 @@ func parseLines(r io.Reader) (*graph, error) { for _, m := range reStartPos.FindAllStringIndex(line, -1) { graph.startPositions = append( graph.startPositions, - point{x: m[0], y: linecount, direction: None}, + point{x: m[0], y: linecount}, ) } @@ -37,9 +37,3 @@ func parseLines(r io.Reader) (*graph, error) { return graph, nil } - -func replaceAtIndex(s string, r rune, i int) string { - out := []rune(s) - out[i] = r - return string(out) -}