# Untitled

Jun 24th, 2021
764
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def in_range(r_row, r_col):
2.     if 0 <= r_row < size and 0 <= r_col < size:
3.         return True
4.     return False
5.
6.
7. def update_neighbours(n_row, n_col):
8.     global matrix
9.     #               UP    RIGHT    DOWN     LEFT      NW        NE      SE      SW
10.     neighbours = (-1, 0), (0, 1), (1, 0), (0, -1), (-1, -1), (-1, 1), (1, 1), (1, -1)
11.     for nei in neighbours:
12.         u_row = n_row + nei[0]
13.         u_col = n_col + nei[1]
14.         if in_range(u_row, u_col):
15.             if isinstance(matrix[u_row][u_col], str):
16.                 continue
17.             else:
18.                 matrix[u_row][u_col] += 1
19.     return
20.
21.
22. def check_for_bomb(b_row, b_col):
23.     for b_index in bombs:
24.         if [b_row, b_col] == b_index:
25.             return True
26.     return False
27.
28.
29. size = int(input())
30. num_bombs = int(input())
31. bombs = []
32. matrix = []
33. for _ in range(num_bombs):
34.     row, col = eval(input())
35.     bombs.append([row, col])
36. matrix = [
37.     ["*" if check_for_bomb(row, col) else 0 for col in range(size)]
38.     for row in range(size)]
39. for bomb in bombs:
40.     update_neighbours(bomb[0], bomb[1])
41.
42. for line in matrix:
43.     print(" ".join([str(_) fo
RAW Paste Data