diff --git a/day-06/internal/one/graph.go b/day-06/internal/one/graph.go index ef58ca1..7cb2d36 100644 --- a/day-06/internal/one/graph.go +++ b/day-06/internal/one/graph.go @@ -2,8 +2,6 @@ package one import ( "strings" - - "github.com/onyx-and-iris/aoc2024/day-06/internal/util" ) type graph struct { @@ -22,7 +20,7 @@ func (g *graph) String() string { func (g *graph) debug(visited map[coords]struct{}) string { for loc := range visited { if !(rune(g.data[loc.Y][loc.X]) == 'O') { - g.data[loc.Y] = util.ReplaceAtIndex(g.data[loc.Y], '+', loc.X) + g.data[loc.Y] = replaceAtIndex(g.data[loc.Y], '+', loc.X) } } diff --git a/day-06/internal/one/solve.go b/day-06/internal/one/solve.go index 0c7c9c4..ff4ae2b 100644 --- a/day-06/internal/one/solve.go +++ b/day-06/internal/one/solve.go @@ -17,13 +17,13 @@ func Solve(buf []byte) (int, error) { log.Debug(graph.startPoint.String()) var count int - count = nextStep(graph.startPoint, graph, Visited, count) + count = nextStep(graph.startPoint, Visited, count, graph) log.Debugf("path walked: \n%s\n", graph.debug(Visited)) return count, nil } -func nextStep(point point, graph *graph, visited map[coords]struct{}, count int) int { +func nextStep(point point, visited map[coords]struct{}, count int, g *graph) int { _, ok := visited[point.coords] if !ok { visited[point.coords] = struct{}{} @@ -34,18 +34,18 @@ func nextStep(point point, graph *graph, visited map[coords]struct{}, count int) if point.X == 0 && point.direction == W || point.Y == 0 && point.direction == N || - point.Y == len(graph.data)-1 && point.direction == S || - point.X == len(graph.data[point.Y])-1 && point.direction == E { + point.Y == len(g.data)-1 && point.direction == S || + point.X == len(g.data[point.Y])-1 && point.direction == E { return count } next := nextPoint(point) log.Debug(next.String()) - log.Debug(string(graph.data[next.Y][next.X])) - if graph.data[next.Y][next.X] == '#' { + log.Debug(string(g.data[next.Y][next.X])) + if g.data[next.Y][next.X] == '#' { next.recalibrate() log.Debugf("switched direction to %d", next.direction) } - return nextStep(next, graph, visited, count) + return nextStep(next, visited, count, g) } diff --git a/day-06/internal/one/util.go b/day-06/internal/one/util.go index 5ad2b68..6d3b1cb 100644 --- a/day-06/internal/one/util.go +++ b/day-06/internal/one/util.go @@ -27,3 +27,9 @@ 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) +} diff --git a/day-06/internal/two/graph.go b/day-06/internal/two/graph.go index ec45ad2..19bbe64 100644 --- a/day-06/internal/two/graph.go +++ b/day-06/internal/two/graph.go @@ -2,8 +2,6 @@ package two import ( "strings" - - "github.com/onyx-and-iris/aoc2024/day-06/internal/util" ) type graph struct { @@ -26,7 +24,7 @@ func (g *graph) valueAt(x, y int) rune { func (g *graph) trace(visited map[point]struct{}) string { for loc := range visited { if !(rune(g.data[loc.y][loc.x]) == 'O') { - g.data[loc.y] = util.ReplaceAtIndex(g.data[loc.y], '+', loc.x) + g.data[loc.y] = replaceAtIndex(g.data[loc.y], '+', loc.x) } } diff --git a/day-06/internal/two/solve.go b/day-06/internal/two/solve.go index f0c82a6..c208f88 100644 --- a/day-06/internal/two/solve.go +++ b/day-06/internal/two/solve.go @@ -54,8 +54,7 @@ func Solve(buf []byte) (int, error) { var numLoops int for range conc { - res := <-isLoop - if res { + if <-isLoop { numLoops++ } } diff --git a/day-06/internal/util/util.go b/day-06/internal/util/util.go deleted file mode 100644 index dd8e76a..0000000 --- a/day-06/internal/util/util.go +++ /dev/null @@ -1,7 +0,0 @@ -package util - -func ReplaceAtIndex(s string, r rune, i int) string { - out := []rune(s) - out[i] = r - return string(out) -}