You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.4 KiB

2 years ago
lines = [ [int(j) for j in list(i)] for i in open("input.txt", 'r').read().splitlines()]
flashes = 0
i = 0
found = False
while i < 99 or not found:
2 years ago
lines = [ [x+1 for x in y] for y in lines]
flashed = True
while flashed:
flashed = False
for x in range(10):
for y in range(10):
if lines[x][y] > 9:
if(i<100):
flashes += 1
2 years ago
lines[x][y] = 0
flashed = True
if x != 0 and lines[x-1][y] != 0:
lines[x-1][y] += 1
if x != 0 and y != 9 and lines[x-1][y+1] != 0:
lines[x-1][y+1] += 1
if y != 9 and lines[x][y+1] != 0:
lines[x][y+1] += 1
if x != 9 and y != 9 and lines[x+1][y+1] != 0:
lines[x+1][y+1] += 1
if x != 9 and lines[x+1][y] != 0:
lines[x+1][y] += 1
if x != 9 and y != 0 and lines[x+1][y-1] != 0:
lines[x+1][y-1] += 1
if y != 0 and lines[x][y-1] != 0:
lines[x][y-1] += 1
if x != 0 and y != 0 and lines[x-1][y-1] != 0:
lines[x-1][y-1] += 1
i += 1
if lines.count([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 10:
print(i)
found = True
2 years ago
print(flashes)