-
Notifications
You must be signed in to change notification settings - Fork 0
/
5.1.py
42 lines (36 loc) · 799 Bytes
/
5.1.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
import re
with open('input/5.txt') as f:
content = f.readlines()
seats = [['O' for x in range(8)] for x in range(128)]
ids = []
for seat in content:
rows = [x for x in range(128)]
columns = [x for x in range(8)]
row_code = seat[:7]
col_code = seat[7:]
print('-----------')
print(seat)
for r in row_code:
mid = int(len(rows)/2)
if r == 'F':
del rows[mid:]
elif r == 'B':
del rows[:mid]
for c in col_code:
mid = int(len(columns)/2)
if c == 'L':
del columns[mid:]
if c == 'R':
del columns[:mid]
r = rows.pop()
c = columns.pop()
id = (r*8)+c
ids.append(id)
seats[r][c] = id
print(r, c, id)
print('-----------')
i = 0
for r in seats:
print(str(i).ljust(3), [str(x).rjust(3) for x in r])
i += 1
print(max(ids))