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
064232967b
commit
fd057f88ed
@ -2,8 +2,6 @@ package one
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-06/internal/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type graph struct {
|
type graph struct {
|
||||||
@ -22,7 +20,7 @@ func (g *graph) String() string {
|
|||||||
func (g *graph) debug(visited map[coords]struct{}) string {
|
func (g *graph) debug(visited map[coords]struct{}) string {
|
||||||
for loc := range visited {
|
for loc := range visited {
|
||||||
if !(rune(g.data[loc.Y][loc.X]) == 'O') {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,13 +17,13 @@ func Solve(buf []byte) (int, error) {
|
|||||||
log.Debug(graph.startPoint.String())
|
log.Debug(graph.startPoint.String())
|
||||||
|
|
||||||
var count int
|
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))
|
log.Debugf("path walked: \n%s\n", graph.debug(Visited))
|
||||||
|
|
||||||
return count, nil
|
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]
|
_, ok := visited[point.coords]
|
||||||
if !ok {
|
if !ok {
|
||||||
visited[point.coords] = struct{}{}
|
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 ||
|
if point.X == 0 && point.direction == W ||
|
||||||
point.Y == 0 && point.direction == N ||
|
point.Y == 0 && point.direction == N ||
|
||||||
point.Y == len(graph.data)-1 && point.direction == S ||
|
point.Y == len(g.data)-1 && point.direction == S ||
|
||||||
point.X == len(graph.data[point.Y])-1 && point.direction == E {
|
point.X == len(g.data[point.Y])-1 && point.direction == E {
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
next := nextPoint(point)
|
next := nextPoint(point)
|
||||||
log.Debug(next.String())
|
log.Debug(next.String())
|
||||||
log.Debug(string(graph.data[next.Y][next.X]))
|
log.Debug(string(g.data[next.Y][next.X]))
|
||||||
if graph.data[next.Y][next.X] == '#' {
|
if g.data[next.Y][next.X] == '#' {
|
||||||
next.recalibrate()
|
next.recalibrate()
|
||||||
log.Debugf("switched direction to %d", next.direction)
|
log.Debugf("switched direction to %d", next.direction)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nextStep(next, graph, visited, count)
|
return nextStep(next, visited, count, g)
|
||||||
}
|
}
|
||||||
|
@ -27,3 +27,9 @@ func parseLines(r io.Reader) (*graph, error) {
|
|||||||
|
|
||||||
return graph, nil
|
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 (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/onyx-and-iris/aoc2024/day-06/internal/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type graph struct {
|
type graph struct {
|
||||||
@ -26,7 +24,7 @@ func (g *graph) valueAt(x, y int) rune {
|
|||||||
func (g *graph) trace(visited map[point]struct{}) string {
|
func (g *graph) trace(visited map[point]struct{}) string {
|
||||||
for loc := range visited {
|
for loc := range visited {
|
||||||
if !(rune(g.data[loc.y][loc.x]) == 'O') {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +54,7 @@ func Solve(buf []byte) (int, error) {
|
|||||||
|
|
||||||
var numLoops int
|
var numLoops int
|
||||||
for range conc {
|
for range conc {
|
||||||
res := <-isLoop
|
if <-isLoop {
|
||||||
if res {
|
|
||||||
numLoops++
|
numLoops++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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