mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 22:30:47 +00:00
remove internal/util
This commit is contained in:
parent
2b675af081
commit
84c1013f2c
@ -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()
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
package util
|
||||
|
||||
func ReplaceAtIndex(s string, r rune, i int) string {
|
||||
out := []rune(s)
|
||||
out[i] = r
|
||||
return string(out)
|
||||
}
|
Loading…
Reference in New Issue
Block a user