-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday69.py
More file actions
46 lines (37 loc) · 1.51 KB
/
day69.py
File metadata and controls
46 lines (37 loc) · 1.51 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/python3
import sys
def createGrid(r, c, grid_at_previous_step):
grid_at_next_step = [['O'] * c for _ in range(r)]
for i in range(r):
for j in range(c):
current_cell = grid_at_previous_step[i][j]
if current_cell == 'O':
grid_at_next_step[i][j] = '.'
if i - 1 >= 0:
grid_at_next_step[i - 1][j] = '.'
if i + 1 <= r - 1:
grid_at_next_step[i + 1][j] = '.'
if j - 1 >= 0:
grid_at_next_step[i][j - 1] = '.'
if j + 1 <= c - 1:
grid_at_next_step[i][j + 1] = '.'
return grid_at_next_step
def bomberMan(n, r, c, initial_grid):
grid_after_first_detonation = createGrid(r, c, initial_grid)
if n % 2 == 0:
return [['O'] * c for _ in range(r)]
elif n < 4:
return initial_grid if n == 1 else grid_after_first_detonation
else:
grid_after_second_detonation = createGrid(r, c, grid_after_first_detonation)
grid_after_third_detonation = createGrid(r, c, grid_after_second_detonation)
return grid_after_second_detonation if n % 4 == 1 else grid_after_third_detonation
if __name__ == "__main__":
r, c, n = input().strip().split(' ')
r, c, n = [int(r), int(c), int(n)]
grid = []
for _ in range(r):
grid.append(list(str(input().strip())))
result = bomberMan(n, r, c, grid)
for row in result:
print("".join(row))