Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def in_range(r_row, r_col):
- if 0 <= r_row < size and 0 <= r_col < size:
- return True
- return False
- def update_neighbours(n_row, n_col):
- global matrix
- # UP RIGHT DOWN LEFT NW NE SE SW
- neighbours = (-1, 0), (0, 1), (1, 0), (0, -1), (-1, -1), (-1, 1), (1, 1), (1, -1)
- for nei in neighbours:
- u_row = n_row + nei[0]
- u_col = n_col + nei[1]
- if in_range(u_row, u_col):
- if isinstance(matrix[u_row][u_col], str):
- continue
- else:
- matrix[u_row][u_col] += 1
- return
- def check_for_bomb(b_row, b_col):
- for b_index in bombs:
- if [b_row, b_col] == b_index:
- return True
- return False
- size = int(input())
- num_bombs = int(input())
- bombs = []
- matrix = []
- for _ in range(num_bombs):
- row, col = eval(input())
- bombs.append([row, col])
- matrix = [
- ["*" if check_for_bomb(row, col) else 0 for col in range(size)]
- for row in range(size)]
- for bomb in bombs:
- update_neighbours(bomb[0], bomb[1])
- for line in matrix:
- print(" ".join([str(_) fo
Advertisement
Add Comment
Please, Sign In to add comment