-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16.1차원라이프게임.py
More file actions
29 lines (26 loc) · 834 Bytes
/
16.1차원라이프게임.py
File metadata and controls
29 lines (26 loc) · 834 Bytes
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
def simulate_life(n, k, cells):
for _ in range(k):
next_cells = cells[:]
for i in range(n):
if i == 0:
neighbors = cells[1]
elif i == n - 1:
neighbors = cells[n - 2]
else:
neighbors = cells[i - 1] + cells[i + 1]
if neighbors < 3 or neighbors > 7:
if cells[i] > 0:
next_cells[i] -= 1
elif 4 <= neighbors <= 7:
if cells[i] < 9:
next_cells[i] += 1
cells = next_cells
return cells
# 입력 처리
if __name__ == '__main__':
T = int(input())
for _ in range(T):
n, k = map(int, input().split())
cells = list(map(int, input().split()))
result = simulate_life(n, k, cells)
print(*result)