aoc2024/day-12/internal/two/explore.go

36 lines
646 B
Go
Raw Permalink Normal View History

2024-12-13 10:02:48 +00:00
package two
import "github.com/onyx-and-iris/aoc2024/day-12/internal/queue"
func exploreAreaSequentially(start point, graph *graph) path {
queue := queue.New[point]()
queue.Enqueue(start)
visited := make(map[point]struct{})
var perimeter int
for !queue.IsEmpty() {
current := queue.Dequeue()
_, ok := visited[current]
if ok {
continue
}
visited[current] = struct{}{}
for _, n := range neighbours(current) {
if graph.isOutOfBounds(n) {
perimeter++
continue
}
if graph.valueAt(n) != graph.valueAt(current) {
perimeter++
continue
}
queue.Enqueue(n)
}
}
return path{visited, perimeter}
}