-
Notifications
You must be signed in to change notification settings - Fork 0
/
codeAdvent_5.py
90 lines (61 loc) · 1.5 KB
/
codeAdvent_5.py
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
84
85
86
87
88
89
90
'''
Created on 26 july 2021
@author: Antonio Martínez Fernández
'''
h_id = 0
row_s = 0
row_e = 127
col_s = 0
col_e = 7
array=[]
# 128 rows 7 char =FRONT->0-mitad BACK->mitad-total
# 8 columns 3 char = R upper half , L lower half
# id = 8* row + column
def procesar(s):
i = 1
global row_s
global row_e
global col_s
global col_e
for c in s:
if(i <= 7 and c == 'B'):
row_s = (row_e+row_s)//2 + 1
elif(i <= 7 and c == 'F'):
row_e = (row_e+row_s)//2
elif(i >= 7 and c == 'L'):
col_e = (col_e+col_s)//2
elif (i >= 7 and c == 'R'):
col_s = (col_e+col_s)//2 + 1
i += 1
return 8*row_s+col_s
def lectura():
global h_id
global row_s
global row_e
global col_s
global col_e
global array
with open('input4.txt') as f:
for linea in f:
aux = procesar(linea)
if(aux > h_id):
h_id = aux
array.append(aux)
row_s = 0
row_e = 127
col_s = 0
col_e = 7
def encontrar_asiento(array):
i=0
for numero in array:
if(i!=len(array)):
if(array[i+1]-numero==2):
return numero+1
i+=1
return 0
if __name__ == '__main__':
lectura()
print(h_id)
array.sort()
print(encontrar_asiento(array))
print(array)