aoc21/d11/p2.go
2022-04-03 22:38:47 +03:00

35 lines
455 B
Go

package d11
func isAllFlashed(grid grid) bool {
for y, line := range grid {
for x := range line {
if !grid[y][x].flashed {
return false
}
}
}
return true
}
func flash2(grid grid) int {
step := 0
for {
for y, line := range grid {
for x := range line {
incr(x, y, grid)
}
}
step++
if isAllFlashed(grid) {
return step
}
reset(grid)
}
}
func P2(in string) int {
grid := createGrid(in)
return flash2(grid)
}