Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_inside(row, col, size):
- return 0 <= row < size and 0 <= col < size
- def nearly_bombs(row, col, matrix):
- size = len(matrix)
- count = 0
- if is_inside(row - 1, col, size) and matrix[row - 1][col] == '*':
- count += 1
- if is_inside(row + 1, col, size) and matrix[row + 1][col] == '*':
- count += 1
- if is_inside(row, col - 1, size) and matrix[row][col - 1] == '*':
- count += 1
- if is_inside(row, col + 1, size) and matrix[row][col + 1] == '*':
- count += 1
- if is_inside(row - 1, col - 1, size) and matrix[row - 1][col - 1] == '*':
- count += 1
- if is_inside(row + 1, col + 1, size) and matrix[row + 1][col + 1] == '*':
- count += 1
- if is_inside(row - 1, col + 1, size) and matrix[row - 1][col + 1] == '*':
- count += 1
- if is_inside(row + 1, col - 1, size) and matrix[row + 1][col - 1] == '*':
- count += 1
- return count
- size = int(input())
- bombs = int(input())
- matrix = []
- for _ in range(size):
- matrix.append([0] * size)
- for _ in range(bombs):
- bomb_row, bom_col = [int(i) for i in input().strip('()').split(', ')]
- if is_inside(bomb_row, bom_col, size):
- matrix[bomb_row][bom_col] = '*'
- for curr_row in range(size):
- for curr_col in range(size):
- if matrix[curr_row][curr_col] == '*':
- continue
- matrix[curr_row][curr_col] = nearly_bombs(curr_row, curr_col, matrix)
- for row in matrix:
- print(*row, sep=' ')
Add Comment
Please, Sign In to add comment