38 lines
1.0 KiB
Plaintext
38 lines
1.0 KiB
Plaintext
Sub anadirNoCelda(celdas As String)
|
|
Dim l As String = Iif(Mid(celdas, 1, 1) = "*", ".", "*")
|
|
Dim r As String = Iif(Mid(celdas, Len(celdas), 1) = "*", ".", "*")
|
|
|
|
For i As Integer = 0 To 1
|
|
celdas = l & celdas & r
|
|
Next
|
|
End Sub
|
|
|
|
Function Paso(celdas As String, regla As Integer) As String
|
|
Dim nuevaCelda As String = ""
|
|
For i As Integer = 0 To Len(celdas) - 3
|
|
Dim bina As Integer = 0
|
|
Dim b As Integer = 2
|
|
For n As Integer = i To i + 2
|
|
bina += Iif(Mid(celdas, n + 1, 1) = "*", 1, 0) * (2 ^ b)
|
|
b -= 1
|
|
Next
|
|
nuevaCelda &= Iif((regla And (1 Shl bina)) <> 0, "*", ".")
|
|
Next
|
|
Return nuevaCelda
|
|
End Function
|
|
|
|
Sub Evolucionar(l As Integer, regla As Integer)
|
|
Print " Rule #" & regla & ":"
|
|
Dim celdas As String = "*"
|
|
For i As Integer = 0 To l - 1
|
|
anadirNoCelda(celdas)
|
|
Dim ancho As Integer = 40 + (Len(celdas) \ 2)
|
|
Print Right(Space(ancho) & celdas, ancho)
|
|
celdas = Paso(celdas, regla)
|
|
Next
|
|
End Sub
|
|
|
|
Evolucionar(35, 90)
|
|
|
|
Sleep
|