pass graph as last arg

This commit is contained in:
onyx-and-iris 2025-01-07 17:24:23 +00:00
parent 84c1013f2c
commit c125230c9b

View File

@ -29,7 +29,7 @@ func Solve(buf []byte) (int, error) {
totalAreaVisited[start] = struct{}{}
path := exploreAreaSequentially(start, graph)
numSides := analyzeSides(graph.valueAt(firstPointFromMap(path.visited)), graph, path)
numSides := analyzeSides(graph.valueAt(firstPointFromMap(path.visited)), path, graph)
totalCost += len(path.visited) * numSides
for point := range path.visited {
@ -47,8 +47,8 @@ const (
diagonal
)
func analyzeSides(kind rune, graph *graph, path path) int {
log.Debugf("graph for values %s\n%s\n", string(kind), graph.debug(path.visited))
func analyzeSides(kind rune, path path, g *graph) int {
log.Debugf("graph for values %s\n%s\n", string(kind), g.debug(path.visited))
var corners int
for current := range path.visited {
@ -60,11 +60,11 @@ func analyzeSides(kind rune, graph *graph, path path) int {
{ns[S], ns[E], point{current.x + 1, current.y + 1}},
{ns[S], ns[W], point{current.x - 1, current.y + 1}},
} {
if isCorner(graph, current, points[first], points[second]) {
if isCorner(current, points[first], points[second], g) {
corners++
}
if isInnerCorner(graph, current, points[first], points[second], points[diagonal]) {
if isInnerCorner(current, points[first], points[second], points[diagonal], g) {
corners++
}
}
@ -75,25 +75,25 @@ func analyzeSides(kind rune, graph *graph, path path) int {
return corners
}
func isCorner(graph *graph, current, p, q point) bool {
if graph.isOutOfBounds(p) && graph.isOutOfBounds(q) {
func isCorner(current, p, q point, g *graph) bool {
if g.isOutOfBounds(p) && g.isOutOfBounds(q) {
return true
}
if !graph.isOutOfBounds(p) {
if graph.isOutOfBounds(q) && !graph.sameKind(p, current) {
if !g.isOutOfBounds(p) {
if g.isOutOfBounds(q) && !g.sameKind(p, current) {
return true
}
}
if !graph.isOutOfBounds(q) {
if graph.isOutOfBounds(p) && !graph.sameKind(q, current) {
if !g.isOutOfBounds(q) {
if g.isOutOfBounds(p) && !g.sameKind(q, current) {
return true
}
}
if !graph.isOutOfBounds(p) && !graph.isOutOfBounds(q) {
if !graph.sameKind(p, current) && !graph.sameKind(q, current) {
if !g.isOutOfBounds(p) && !g.isOutOfBounds(q) {
if !g.sameKind(p, current) && !g.sameKind(q, current) {
return true
}
}
@ -101,10 +101,10 @@ func isCorner(graph *graph, current, p, q point) bool {
return false
}
func isInnerCorner(graph *graph, current, p, q, diagonal point) bool {
if !graph.isOutOfBounds(p) && !graph.isOutOfBounds(q) {
if graph.sameKind(p, current) && graph.sameKind(q, current) &&
!graph.sameKind(diagonal, current) {
func isInnerCorner(current, p, q, diagonal point, g *graph) bool {
if !g.isOutOfBounds(p) && !g.isOutOfBounds(q) {
if g.sameKind(p, current) && g.sameKind(q, current) &&
!g.sameKind(diagonal, current) {
return true
}
}