diff --git a/day-08/internal/one/graph.go b/day-08/internal/one/graph.go index d85a752..8d3031b 100644 --- a/day-08/internal/one/graph.go +++ b/day-08/internal/one/graph.go @@ -2,8 +2,6 @@ package one import ( "strings" - - "github.com/onyx-and-iris/aoc2024/day-08/internal/util" ) type graph struct { @@ -26,10 +24,10 @@ func (g *graph) isOutOfBounds(c coords) bool { func (g *graph) debug() string { for _, antenna := range g.antennae { - g.data[antenna.y] = util.ReplaceAtIndex(g.data[antenna.y], antenna.identifier, antenna.x) + g.data[antenna.y] = replaceAtIndex(g.data[antenna.y], antenna.identifier, antenna.x) } for antinode := range g.antinodes { - g.data[antinode.y] = util.ReplaceAtIndex(g.data[antinode.y], '#', antinode.x) + g.data[antinode.y] = replaceAtIndex(g.data[antinode.y], '#', antinode.x) } return g.String() diff --git a/day-08/internal/one/util.go b/day-08/internal/one/util.go index 76fff67..3a7bc41 100644 --- a/day-08/internal/one/util.go +++ b/day-08/internal/one/util.go @@ -32,3 +32,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-08/internal/two/graph.go b/day-08/internal/two/graph.go index 9d06da5..f61fccd 100644 --- a/day-08/internal/two/graph.go +++ b/day-08/internal/two/graph.go @@ -2,8 +2,6 @@ package two import ( "strings" - - "github.com/onyx-and-iris/aoc2024/day-08/internal/util" ) type graph struct { @@ -26,10 +24,10 @@ func (g *graph) isOutOfBounds(c coords) bool { func (g *graph) debug() string { for _, antenna := range g.antennae { - g.data[antenna.y] = util.ReplaceAtIndex(g.data[antenna.y], antenna.identifier, antenna.x) + g.data[antenna.y] = replaceAtIndex(g.data[antenna.y], antenna.identifier, antenna.x) } for antinode := range g.antinodes.data { - g.data[antinode.y] = util.ReplaceAtIndex(g.data[antinode.y], '#', antinode.x) + g.data[antinode.y] = replaceAtIndex(g.data[antinode.y], '#', antinode.x) } return g.String() diff --git a/day-08/internal/two/solve.go b/day-08/internal/two/solve.go index 3ab1650..1c06c85 100644 --- a/day-08/internal/two/solve.go +++ b/day-08/internal/two/solve.go @@ -27,8 +27,7 @@ func Solve(buf []byte) (int, error) { continue } - all := []coords{a.coords, b.coords} - for _, coords := range calcAntiNodePos(a.coords, b.coords, graph, all) { + for _, coords := range calcAntiNodePos(a.coords, b.coords, []coords{a.coords, b.coords}, graph) { if !graph.antinodes.contains(coords) { graph.antinodes.insert(coords) } @@ -44,7 +43,7 @@ func Solve(buf []byte) (int, error) { return graph.antinodes.len(), nil } -func calcAntiNodePos(a, b coords, graph *graph, all []coords) []coords { +func calcAntiNodePos(a, b coords, all []coords, g *graph) []coords { xdiff := int(math.Abs(float64(a.x - b.x))) ydiff := int(math.Abs(float64(a.y - b.y))) @@ -59,8 +58,8 @@ func calcAntiNodePos(a, b coords, graph *graph, all []coords) []coords { next = newCoords(b.x-xdiff, b.y-ydiff) } - if graph.isOutOfBounds(next) { + if g.isOutOfBounds(next) { return all } - return calcAntiNodePos(b, next, graph, append(all, next)) + return calcAntiNodePos(b, next, append(all, next), g) } diff --git a/day-08/internal/two/util.go b/day-08/internal/two/util.go index 68b69cb..875a5fe 100644 --- a/day-08/internal/two/util.go +++ b/day-08/internal/two/util.go @@ -32,3 +32,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-08/internal/util/util.go b/day-08/internal/util/util.go deleted file mode 100644 index dd8e76a..0000000 --- a/day-08/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) -}