mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 14:20:48 +00:00
and a little more
This commit is contained in:
parent
dcf3479d88
commit
7b17f8edc1
@ -41,6 +41,12 @@ func Solve(buf []byte) (int, error) {
|
||||
return totalCost, nil
|
||||
}
|
||||
|
||||
const (
|
||||
first = iota
|
||||
second
|
||||
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))
|
||||
|
||||
@ -48,23 +54,20 @@ func analyzeSides(kind rune, graph *graph, path path) int {
|
||||
for current := range path.visited {
|
||||
ns := neighbours(current)
|
||||
|
||||
if isCorner(graph, current, ns[N], ns[E]) {
|
||||
corners++
|
||||
}
|
||||
for _, points := range [][]point{
|
||||
{ns[N], ns[E], point{current.x + 1, current.y - 1}},
|
||||
{ns[N], ns[W], 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}},
|
||||
} {
|
||||
if isCorner(graph, current, points[first], points[second]) {
|
||||
corners++
|
||||
}
|
||||
|
||||
if isCorner(graph, current, ns[S], ns[E]) {
|
||||
corners++
|
||||
if isInnerCorner(graph, current, points[first], points[second], points[diagonal]) {
|
||||
corners++
|
||||
}
|
||||
}
|
||||
|
||||
if isCorner(graph, current, ns[N], ns[W]) {
|
||||
corners++
|
||||
}
|
||||
|
||||
if isCorner(graph, current, ns[S], ns[W]) {
|
||||
corners++
|
||||
}
|
||||
|
||||
corners += numInnerCorner(graph, current, ns)
|
||||
}
|
||||
|
||||
log.Debugf("this path has %d corners", corners)
|
||||
@ -98,28 +101,6 @@ func isCorner(graph *graph, current, p, q point) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func numInnerCorner(graph *graph, current point, ns [4]point) int {
|
||||
var corners int
|
||||
|
||||
if isInnerCorner(graph, current, ns[N], ns[E], point{current.x + 1, current.y - 1}) {
|
||||
corners++
|
||||
}
|
||||
|
||||
if isInnerCorner(graph, current, ns[N], ns[W], point{current.x - 1, current.y - 1}) {
|
||||
corners++
|
||||
}
|
||||
|
||||
if isInnerCorner(graph, current, ns[S], ns[E], point{current.x + 1, current.y + 1}) {
|
||||
corners++
|
||||
}
|
||||
|
||||
if isInnerCorner(graph, current, ns[S], ns[W], point{current.x - 1, current.y + 1}) {
|
||||
corners++
|
||||
}
|
||||
|
||||
return corners
|
||||
}
|
||||
|
||||
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) &&
|
||||
|
Loading…
Reference in New Issue
Block a user