mirror of
				https://github.com/onyx-and-iris/aoc2024.git
				synced 2025-11-04 06:51:47 +00:00 
			
		
		
		
	remove internal/util
This commit is contained in:
		
							parent
							
								
									064232967b
								
							
						
					
					
						commit
						fd057f88ed
					
				@ -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)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -54,8 +54,7 @@ func Solve(buf []byte) (int, error) {
 | 
			
		||||
 | 
			
		||||
	var numLoops int
 | 
			
		||||
	for range conc {
 | 
			
		||||
		res := <-isLoop
 | 
			
		||||
		if res {
 | 
			
		||||
		if <-isLoop {
 | 
			
		||||
			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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user