This commit is contained in:
2021-12-20 22:41:29 +01:00
parent ce02b1c91b
commit e3c1f47592
6 changed files with 85 additions and 4 deletions

29
d11/d11_1.py Normal file
View File

@@ -0,0 +1,29 @@
import sys
L = list(map(lambda s: [-999]+list(map(int, s))+[-999] ,sys.stdin.read().splitlines()))
L = [[-999]*12] + L + [[-999]*12]
def printgrid():
for row in L[1:-1]:
print("".join(map(str,row[1:-1])))
printgrid()
N = 0
for s in range(100):
D = set()
print("step",s+1)
for x in range(1,11):
for y in range(1,11):
L[x][y] += 1
flash = True
while flash:
flash = False
for x in range(1,11):
for y in range(1,11):
curr = L[x][y]
if curr > 9:
flash = True
for (i,j) in [(0,1),(1,0),(-1,0),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)]:
L[x+i][y+j] += 1 if (x+i,y+j) not in D else 0
N+=1
L[x][y] = 0
D.add((x,y)) # can't increase its energy for the rest of the turn
printgrid()
print(N)

32
d11/d11_2.py Normal file
View File

@@ -0,0 +1,32 @@
import sys
L = list(map(lambda s: [-999]+list(map(int, s))+[-999] ,sys.stdin.read().splitlines()))
L = [[-999]*12] + L + [[-999]*12]
def printgrid():
for row in L[1:-1]:
print("".join(map(str,row[1:-1])))
printgrid()
N = []
for s in range(1000):
D = set()
print("step",s+1)
for x in range(1,11):
for y in range(1,11):
L[x][y] += 1
flash = True
while flash:
flash = False
for x in range(1,11):
for y in range(1,11):
curr = L[x][y]
if curr > 9:
flash = True
for (i,j) in [(0,1),(1,0),(-1,0),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)]:
L[x+i][y+j] += 1 if (x+i,y+j) not in D else 0
#N+=1
L[x][y] = 0
D.add((x,y)) # can't increase its energy for the rest of the turn
if len(D) == 100:
print(s)
N.append(s)
printgrid()
print(N[0]+1)

10
d11/input Normal file
View File

@@ -0,0 +1,10 @@
1172728874
6751454281
2612343533
1884877511
7574346247
2117413745
7766736517
4331783444
4841215828
6857766273

10
d11/sample Normal file
View File

@@ -0,0 +1,10 @@
5483143223
2745854711
5264556173
6141336146
6357385478
4167524645
2176841721
6882881134
4846848554
5283751526