-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolution.py
29 lines (20 loc) · 812 Bytes
/
solution.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
def detect_bombs(grid: list[list[bool]]) -> list[list[int]]:
adjacents_bombs: list[list[int]] = []
for i, row in enumerate(iterable=grid):
bombs_in_row: list[int] = []
for j, cell in enumerate(iterable=row):
start_i: int = i - 1
stop_i: int = i + 2
start_j: int = j - 1
stop_j: int = j + 2
bombs = 0
for _i in range(start_i, stop_i):
if _i < 0 or _i > len(grid) - 1:
continue
for _j in range(start_j, stop_j):
if _j < 0 or _j > len(row) - 1:
continue
bombs += grid[_i][_j]
bombs_in_row.append(bombs - cell)
adjacents_bombs.append(bombs_in_row)
return adjacents_bombs