Con el mismo formulario que en mi post anterior o el del Re: Advent of Code 2021 Problema 9.
pero uso este código
Public x As IntegerPublic y As Integer
Public stack As Integer
Public D(1 To 100, 1 To 100) As Integer
Public res(1 To 10000, 1 To 3) As Integer
Private Sub Command1_Click()
n = fila.Text * columna.Text
x = 1
y = 1
Do Until x = fila.Text + 1
Do Until y = columna.Text + 1
leyenda.Caption = " intoduzca dato de fila " & x & " y columna " & y
y = y + 1
Loop
x = x + 1
Loop
x = 1
y = 1
c = 0
paso = 1
destellos = 0
stack = 0
Do Until paso = 101
Do Until x = fila.Text + 1
Do Until y = columna.Text + 1
If D(x, y) > 9 Then
destellos = destellos + 1
Call destella(x, y)
End If
x = x + 1
Loop
y = y + 1
Loop
x = 1
y = 1
Do Until x = fila.Text + 1
Do Until y = columna.Text + 1
D(x, y) = D(x, y) + 1
x = x + 1
Loop
y = y + 1
Loop
stack = 0
paso = paso + 1
Loop
resultado.Caption = "El resultado es " & destellos
End Sub
Private Sub Command2_Click()
D(x, y) = Dato.Text + 1
Dato.Text = ""
End Sub
Public Sub destella(ByVal xi As Integer, ByVal yi As Integer)
xu = xi - 1
xd = xi + 1
yl = yi - 1
yr = yi + 1
If D(xi, yi) >= 10 Then
D(xi, yi) = 0
' codi
If xu > 0 And yl > 0 And D(xu, yl) <> 0 Then
D(xu, yl) = D(xu, yl) + 1
If D(xu, yl) > 9 Then
stack = stack + 1
res(stack, 1) = xu
res(stack, 2) = yl
End If
End If
If xu > 0 And yi > 0 And D(xu, yi) <> 0 Then
D(xu, yi) = D(xu, yi) + 1
If D(xu, yi) > 9 Then
stack = stack + 1
res(stack, 1) = xu
res(stack, 2) = yi
End If
End If
If xu > 0 And yr < columna.Text + 1 And D(xu, yr) <> 0 Then
D(xu, yr) = D(xu, yr) + 1
If D(xu, yr) > 9 Then
stack = stack + 1
res(stack, 1) = xu
res(stack, 2) = yr
End If
End If
If xi > 0 And yl > 0 And D(xi, yl) <> 0 Then
D(xi, yl) = D(xi, yl) + 1
If D(xi, yl) > 9 Then
stack = stack + 1
res(stack, 1) = xi
res(stack, 2) = yl
End If
End If
If xi > 0 And yr < columna.Text + 1 And D(xi, yr) <> 0 Then
D(xi, yr) = D(xi, yr) + 1
If D(xi, yr) > 9 Then
stack = stack + 1
res(stack, 1) = xi
res(stack, 2) = yr
End If
End If
If xd < fila.Text + 1 And yl > 0 And D(xd, yl) <> 0 Then
D(xd, yl) = D(xd, yl) + 1
If D(xd, yl) > 9 Then
stack = stack + 1
res(stack, 1) = xd
res(stack, 2) = yl
End If
End If
If xd < fila.Text + 1 And yi > 0 And D(xd, yi) <> 0 Then
D(xd, yi) = D(xd, yi) + 1
If D(xd, yi) > 9 Then
stack = stack + 1
res(stack, 1) = xd
res(stack, 2) = yi
End If
End If
If xd < fila.Text + 1 And yr < columna.Text + 1 And D(xd, yr) <> 0 Then
D(xd, yr) = D(xd, yr) + 1
If D(xd, yr) > 9 Then
stack = stack + 1
res(stack, 1) = xd
res(stack, 2) = yr
End If
End If
If stack <> 0 Then
xn = res(stack, 1)
yn = res(stack, 2)
res(stack, 1) = 0
res(stack, 2) = 0
stack = stack - 1
destellos = destellos + 1
Call destella(xn, yn)
End If
End Sub
Resumo,Cargo la lista de 10x10 ya le sumo 1 a cada valor
Inicio contador de pasos
Busco destellos \( x>9 \)
Si hay destellos propago a los vecinos
Los vecinos que destellan los guardo en un stack "para eso lo pidieron programar antes"
Luego de propagar el destello, cargo el siguiente destello del stack.
Reitero los dos pasos anteriores sabiendo que la propagación no afecta a las casillas con 0 de energía
Cuando el stack vuelve a cero continua buscando en la tabla hasta el final
Llevando contadores se cuentan el total de destellos.
No he puesto sentencias de control de errores
Saludos