5SNQFHZA6PBWJ6HT3SUKIRWKFTKMKLFPYWC73EQKATABBVKUJYPQC
func solveSecond(m matrix) int {
var step int
for ; ; step++ {
for row := range m {
for col := range m[0] {
m[row][col]++
}
}
s := seen{}
for row := range m {
for col := range m[0] {
s.flash(m, row, col)
}
}
s = seen{} // reset flashes
for row := range m {
for col := range m[0] {
if m[row][col] > 9 {
m[row][col] = 0
}
}
}
if m.fullFlash() {
break
}
}
return step + 1
}
func (m matrix) fullFlash() bool {
for row := range m {
for col := range m[0] {
if m[row][col] != 0 {
return false
}
}
}
return true
}