-
Notifications
You must be signed in to change notification settings - Fork 0
/
IBM Feb2021 Challenge.vb
83 lines (69 loc) · 2.02 KB
/
IBM Feb2021 Challenge.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Option Explicit
Dim BinGrid(), vacunados() As String
Dim largo, ancho As Integer
Dim posiblesResp() As Integer
Dim filas, columnas As Integer
Sub programa()
Dim iterador As Integer
initData
For iterador = 1 To 5
recorredor
Next
printer
End Sub
Sub initData()
Dim fila, columna As Integer
filas = Range("BinGrid").Rows.Count
columnas = Range("BinGrid").Columns.Count
ReDim BinGrid(filas + 1, columnas + 1)
ReDim vacunados(filas + 1, columnas + 1)
For fila = 1 To filas
For columna = 1 To columnas
BinGrid(fila, columna) = Range("BinGrid").Cells(fila, columna)
vacunados(fila, columna) = 0
If fila = 1 Then
vacunados(fila - 1, columna) = 1
End If
If columna = 1 Then
vacunados(fila, columna - 1) = 1
End If
If fila = 12 Then
vacunados(fila + 1, columna) = 1
End If
If columna = 12 Then
vacunados(fila, columna + 1) = 1
End If
Next
Next
End Sub
Sub recorredor()
Dim fila, columna, vacunar As Integer
For fila = 1 To filas
For columna = 1 To columnas
vacunar = 0
If Mid(BinGrid(fila, columna), 1, 1) = 0 Or vacunados(fila - 1, columna) = 1 Then
vacunar = vacunar + 1
End If
If Mid(BinGrid(fila, columna), 2, 1) = 0 Or vacunados(fila, columna + 1) = 1 Then
vacunar = vacunar + 1
End If
If Mid(BinGrid(fila, columna), 3, 1) = 0 Or vacunados(fila + 1, columna) = 1 Then
vacunar = vacunar + 1
End If
If Mid(BinGrid(fila, columna), 4, 1) = 0 Or vacunados(fila, columna - 1) = 1 Then
vacunar = vacunar + 1
End If
If vacunar = 4 Then
vacunados(fila, columna) = 1
End If
Next
Next
End Sub
Sub printer()
Dim fila, columna, vacunar As Integer
For fila = 1 To filas
For columna = 1 To columnas
Sheet2.Cells(fila, columna).Value = vacunados(fila, columna)
Next
Next
End Sub