-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminesweeper.py
More file actions
29 lines (29 loc) · 1.14 KB
/
minesweeper.py
File metadata and controls
29 lines (29 loc) · 1.14 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
def solution(matrix):
num_rows = len(matrix)
num_columns = len(matrix[0])
output = []
for row in range(len(matrix)):
r = []
output.append(r)
for column in range(len(matrix[0])):
output[row].append(int("0"))
for row in range(len(matrix)):
for column in range(len(matrix[0])):
if matrix[row][column] == True:
if column + 1 < num_columns:
output[row][column+1] += 1
if column > 0:
output[row][column-1] += 1
if row + 1 < num_rows:
output[row+1][column] += 1
if row > 0:
output[row-1][column] += 1
if column > 0 and row > 0:
output[row-1][column-1] += 1
if column + 1 < num_columns and row + 1 < num_rows:
output[row+1][column+1] += 1
if row + 1 < num_rows and column > 0:
output[row+1][column-1] += 1
if row > 0 and column + 1 < num_columns:
output[row-1][column+1] += 1
return output