mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 22:30:47 +00:00
pass graph as last arg
This commit is contained in:
parent
84c1013f2c
commit
c125230c9b
@ -29,7 +29,7 @@ func Solve(buf []byte) (int, error) {
|
|||||||
totalAreaVisited[start] = struct{}{}
|
totalAreaVisited[start] = struct{}{}
|
||||||
|
|
||||||
path := exploreAreaSequentially(start, graph)
|
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
|
totalCost += len(path.visited) * numSides
|
||||||
for point := range path.visited {
|
for point := range path.visited {
|
||||||
@ -47,8 +47,8 @@ const (
|
|||||||
diagonal
|
diagonal
|
||||||
)
|
)
|
||||||
|
|
||||||
func analyzeSides(kind rune, graph *graph, path path) int {
|
func analyzeSides(kind rune, path path, g *graph) int {
|
||||||
log.Debugf("graph for values %s\n%s\n", string(kind), graph.debug(path.visited))
|
log.Debugf("graph for values %s\n%s\n", string(kind), g.debug(path.visited))
|
||||||
|
|
||||||
var corners int
|
var corners int
|
||||||
for current := range path.visited {
|
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[E], point{current.x + 1, current.y + 1}},
|
||||||
{ns[S], ns[W], 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++
|
corners++
|
||||||
}
|
}
|
||||||
|
|
||||||
if isInnerCorner(graph, current, points[first], points[second], points[diagonal]) {
|
if isInnerCorner(current, points[first], points[second], points[diagonal], g) {
|
||||||
corners++
|
corners++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,25 +75,25 @@ func analyzeSides(kind rune, graph *graph, path path) int {
|
|||||||
return corners
|
return corners
|
||||||
}
|
}
|
||||||
|
|
||||||
func isCorner(graph *graph, current, p, q point) bool {
|
func isCorner(current, p, q point, g *graph) bool {
|
||||||
if graph.isOutOfBounds(p) && graph.isOutOfBounds(q) {
|
if g.isOutOfBounds(p) && g.isOutOfBounds(q) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if !graph.isOutOfBounds(p) {
|
if !g.isOutOfBounds(p) {
|
||||||
if graph.isOutOfBounds(q) && !graph.sameKind(p, current) {
|
if g.isOutOfBounds(q) && !g.sameKind(p, current) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !graph.isOutOfBounds(q) {
|
if !g.isOutOfBounds(q) {
|
||||||
if graph.isOutOfBounds(p) && !graph.sameKind(q, current) {
|
if g.isOutOfBounds(p) && !g.sameKind(q, current) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !graph.isOutOfBounds(p) && !graph.isOutOfBounds(q) {
|
if !g.isOutOfBounds(p) && !g.isOutOfBounds(q) {
|
||||||
if !graph.sameKind(p, current) && !graph.sameKind(q, current) {
|
if !g.sameKind(p, current) && !g.sameKind(q, current) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,10 +101,10 @@ func isCorner(graph *graph, current, p, q point) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func isInnerCorner(graph *graph, current, p, q, diagonal point) bool {
|
func isInnerCorner(current, p, q, diagonal point, g *graph) bool {
|
||||||
if !graph.isOutOfBounds(p) && !graph.isOutOfBounds(q) {
|
if !g.isOutOfBounds(p) && !g.isOutOfBounds(q) {
|
||||||
if graph.sameKind(p, current) && graph.sameKind(q, current) &&
|
if g.sameKind(p, current) && g.sameKind(q, current) &&
|
||||||
!graph.sameKind(diagonal, current) {
|
!g.sameKind(diagonal, current) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user