mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
36 lines
646 B
Go
36 lines
646 B
Go
|
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}
|
||
|
}
|