-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpartOne.py
More file actions
34 lines (22 loc) · 841 Bytes
/
Copy pathpartOne.py
File metadata and controls
34 lines (22 loc) · 841 Bytes
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
from typing import List, Tuple
from common import *
def get_new_state(num_neighbours: int, old_state: str) -> str:
if num_neighbours == 0:
return filled_seat
elif num_neighbours >= 4 and old_state == filled_seat:
return open_seat
return old_state
def count_neighbours(
hall: List[List[str]], current_pos: Tuple[int, int], hall_size: Tuple[int, int]
) -> int:
num_neighbours = 0
row, col = current_pos
for (x, y) in lookup_positions:
test_x_pos = x + col
test_y_pos = y + row
if 0 <= test_x_pos < hall_size[0] and 0 <= test_y_pos < hall_size[1]:
if hall[test_y_pos][test_x_pos] == filled_seat:
num_neighbours += 1
return num_neighbours
def partOne(instr: str) -> int:
return run(parse(instr), count_neighbours, get_new_state)