-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpartTwo.py
More file actions
41 lines (30 loc) · 1.03 KB
/
partTwo.py
File metadata and controls
41 lines (30 loc) · 1.03 KB
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
from common import *
def partTwo(instr: str) -> int:
input_list = parse(instr)
# Build a matrix to represent the entire plane
# False represents an empty seat
seat_matrix = []
for _ in range(num_rows):
x = []
for _ in range(num_cols):
x.append(False)
seat_matrix.append(x)
# Populate that matrix
for seat in input_list:
row, col = parse_seat(seat)
seat_matrix[row][col] = True
lastOne = None
lastTwo = None
for row in range(len(seat_matrix)):
for col in range(len(seat_matrix[row])):
this = seat_matrix[row][col]
if [lastTwo, lastOne, this] == [True, False, True]:
# We need to get the previous item because at this point, we've already moved on one
prev_row = row
prev_col = col - 1
if prev_col < 0:
prev_row -= 1
return get_seat_id(prev_row, prev_col)
lastTwo = lastOne
lastOne = this
return 0