-
Notifications
You must be signed in to change notification settings - Fork 0
/
jogovida.py
50 lines (42 loc) · 1.03 KB
/
jogovida.py
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
47
48
49
50
from copy import deepcopy
def muda_estado(atual,past,i,j):
global L
global C
cont=0
for k in [-1,0,1]:
for l in [-1,0,1]:
if i+k>=0 and i+k<L and j+l>=0 and j+l<C:
cont += past[i+k][j+l]
cont -= past[i][j]
if cont<2 and past[i][j]==1:
atual[i][j] = 0
elif cont>3 and past[i][j]==1:
atual[i][j] = 0
elif cont == 3 and past[i][j]==0:
atual[i][j] = 1
elif (cont == 2 or cont == 3) and past[i][j]==1:
atual[i][j] = 1
L,C = input().split()
L = int(L)
C = int(C)
atual = []
past = []
for i in range(0,L):
entrada = input().split()
past=[]
for j in range(0,C):
past.append(int(entrada[j]))
atual.append(past)
past = deepcopy(atual)
tempo = int(input())
for t in range(0,tempo):
for i in range(0,L):
for j in range(0,C):
muda_estado(atual,past,i,j)
past = deepcopy(atual)
res = ''
for i in range(0,L):
for j in range(0,C):
res += f'{past[i][j]}'
res+='\n'
print(res[0:len(res)-1])