Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def check_next_el(matrix, row, col):
- positions = [(-1, 0), (-1, -1), (-1, 1), (0, -1), (0, 1), (1, 0), (1, -1), (1, 1)]
- counter = 0
- for position in positions:
- potential_row = row + position[0]
- potential_col = col + position[1]
- if is_valid_bound(potential_row, potential_col, len(matrix)):
- potential_position = matrix[potential_row][potential_col]
- if potential_position == '*':
- counter += 1
- return counter
- def is_valid_bound(row, col, length):
- return 0 <= row < length and 0 <= col < length
- size_matrix = int(input())
- number_bombs = int(input())
- matrix = []
- for i in range(size_matrix):
- matrix.append([])
- for j in range(size_matrix):
- matrix[i].append(0)
- for _ in range(number_bombs):
- tokens = input()
- row = int(tokens[1])
- col = int(tokens[4])
- matrix[row][col] = '*'
- for row_idx in range(size_matrix):
- for col_idx in range(size_matrix):
- if matrix[row_idx][col_idx] != '*':
- counter = check_next_el(matrix, row_idx, col_idx)
- matrix[row_idx][col_idx] = counter
- for row in matrix:
- print(' '.join([str(x) for x in row]))
Advertisement
Add Comment
Please, Sign In to add comment