Advent of Code 2020, now in the most terse and awful python possible
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.

47 lines
1.2 KiB

#!/usr/bin/env python3
from sys import argv
i = [list(x.strip()) for x in open(argv[1])]
w = len(i[0])
h = len(i)
d = (
(-1,-1), (-1, 0), (-1,+1),
( 0,-1), ( 0,+1),
(+1,-1), (+1, 0), (+1,+1)
)
def f(p2):
o = i
while True:
n = [[None]*w for x in range(h)]
for y, iy in enumerate(o):
for x, c in enumerate(iy):
a = 0
for v in d:
cy = y+v[0]
cx = x+v[1]
while cy >= 0 and cx >= 0 and cy < h and cx < w:
cc = o[cy][cx]
if cc == "#":
a += 1
break
if cc == "L" or not p2:
break
cy += v[0]
cx += v[1]
if c == "L" and a == 0:
n[y][x] = "#"
continue
if c == "#" and a >= (4 if not p2 else 5):
n[y][x] = "L"
continue
n[y][x] = c
if str(n) == str(o):
return n
o = n
print(sum(x.count("#") for x in f(False)))
print(sum(x.count("#") for x in f(True)))