Remove helper script

Signed-off-by: AKU <tom@tdpain.net>
This commit is contained in:
akp 2021-12-20 10:58:38 +00:00
parent 2f656992e8
commit 16914cc28d
No known key found for this signature in database
GPG key ID: AA5726202C8879B7

View file

@ -1,48 +0,0 @@
import sys
def parse(f):
yield [char == "#" for char in f.readline().rstrip()]
f.readline()
yield {
(x, y) for y, line in enumerate(f) for x, char in enumerate(line) if char == "#"
}
def index(x, y, is_light):
i = 0
for ny in range(y - 1, y + 2):
for nx in range(x - 1, x + 2):
i = i << 1 | is_light(nx, ny)
return i
def enhance(light, algo, step):
xmin = min(x for x, y in light)
xmax = max(x for x, y in light)
ymin = min(y for x, y in light)
ymax = max(y for x, y in light)
def is_light(x, y):
if algo[0] and not (xmin <= x <= xmax and ymin <= y <= ymax):
return step % 2
return (x, y) in light
return {
(x, y)
for y in range(ymin - 1, ymax + 2)
for x in range(xmin - 1, xmax + 2)
if algo[index(x, y, is_light)]
}
def enhance_times(light, algo, times):
for step in range(times):
light = enhance(light, algo, step)
return light
with open("input.txt") as f:
algo, light = parse(f)
print(len(enhance_times(light, algo, 2)))
print(len(enhance_times(light, algo, 50)))