diff --git a/day-12/internal/two/solve.go b/day-12/internal/two/solve.go index ec78c5a..b4625a7 100644 --- a/day-12/internal/two/solve.go +++ b/day-12/internal/two/solve.go @@ -101,33 +101,31 @@ func isCorner(graph *graph, current, p, q point) bool { func numInnerCorner(graph *graph, current point, ns [4]point) int { var corners int - if !graph.isOutOfBounds(ns[N]) && !graph.isOutOfBounds(ns[E]) { - if graph.sameKind(ns[N], current) && graph.sameKind(ns[E], current) && - !graph.sameKind(point{current.x + 1, current.y - 1}, current) { - corners++ - } + if isInnerCorner(graph, current, ns[N], ns[E], point{current.x + 1, current.y - 1}) { + corners++ } - if !graph.isOutOfBounds(ns[N]) && !graph.isOutOfBounds(ns[W]) { - if graph.sameKind(ns[N], current) && graph.sameKind(ns[W], current) && - !graph.sameKind(point{current.x - 1, current.y - 1}, current) { - corners++ - } + if isInnerCorner(graph, current, ns[N], ns[W], point{current.x - 1, current.y - 1}) { + corners++ } - if !graph.isOutOfBounds(ns[S]) && !graph.isOutOfBounds(ns[E]) { - if graph.sameKind(ns[S], current) && graph.sameKind(ns[E], current) && - !graph.sameKind(point{current.x + 1, current.y + 1}, current) { - corners++ - } + if isInnerCorner(graph, current, ns[S], ns[E], point{current.x + 1, current.y + 1}) { + corners++ } - if !graph.isOutOfBounds(ns[S]) && !graph.isOutOfBounds(ns[W]) { - if graph.sameKind(ns[S], current) && graph.sameKind(ns[W], current) && - !graph.sameKind(point{current.x - 1, current.y + 1}, current) { - 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) && + !graph.sameKind(diagonal, current) { + return true + } + } + return false +}