-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday11foo.py
More file actions
46 lines (40 loc) · 1.09 KB
/
day11foo.py
File metadata and controls
46 lines (40 loc) · 1.09 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
grid = [
list(map(int, 7232374314)),
list(map(int, 8531113786)),
list(map(int, 3411787828)),
list(map(int, 5482241344)),
list(map(int, 5856827742)),
list(map(int, 7614532764)),
list(map(int, 5311321758)),
list(map(int, 1255116187)),
list(map(int, 5821277714)),
list(map(int, 2623834788))
]
#grid = [list(map(int, line)) for line in lines]
print(grid)
f = 0
def flash(grid, r, c):
global f
f += 1
for i in range(r - 1, r + 2):
for j in range(c - 1, c + 2):
if i == r and j == c: continue
if 0 <= i < len(grid) and 0 <= j < len(grid[i]):
grid[i][j] += 1
if grid[i][j] == 10:
flash(grid, i, j)
grid[i][j] += 1
def step(grid):
for r in range(len(grid)):
for c in range(len(grid[r])):
grid[r][c] += 1
if grid[r][c] == 10:
flash(grid, r, c)
grid[r][c] += 1
for r in range(len(grid)):
for c in range(len(grid[r])):
if grid[r][c] > 9:
grid[r][c] = 0
for _ in range(100):
step(grid)
print(f)