This commit is contained in:
Sebastian Seedorf
2021-12-12 12:31:54 +01:00
parent 9db0c549e4
commit 2f6cbeb1db
3 changed files with 58 additions and 0 deletions

10
day11/input.txt Normal file
View File

@@ -0,0 +1,10 @@
6636827465
6774248431
4227386366
7447452613
6223122545
2814388766
6615551144
4836235836
5334783256
4128344843

24
day11/part1.py Normal file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env python3
import numpy as np
from scipy.signal import convolve2d
arr = np.array([[int(n) for n in line.strip()] for line in open("input.txt")])
flashes = 0
for step in range(100):
arr = arr + 1
next_arr = arr
mask = np.zeros_like(arr)
changes = 0
while True:
mask[next_arr >= 10] = 1
next_arr = arr + convolve2d(mask, np.array([[1, 1, 1], [1, 0, 1], [1, 1, 1]]), boundary='fill', mode='same')
if changes == (changes := np.sum(mask)):
arr = next_arr
arr[arr >= 10] = 0
flashes += np.sum(mask)
break
print(flashes)

24
day11/part2.py Normal file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env python3
from functools import reduce
import numpy as np
from scipy.signal import convolve2d
arr = np.array([[int(n) for n in line.strip()] for line in open("input.txt")])
for step in range(1000):
arr = arr + 1
next_arr = arr
mask = np.zeros_like(arr)
changes = 0
while True:
mask[next_arr >= 10] = 1
next_arr = arr + convolve2d(mask, np.array([[1, 1, 1], [1, 0, 1], [1, 1, 1]]), boundary='fill', mode='same')
if changes == (changes := np.sum(mask)):
arr = next_arr
arr[arr >= 10] = 0
if np.sum(mask) == reduce(lambda a, b: a*b, arr.shape):
print(step + 1)
exit(0)
break