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.
 
 

25 lines
674 B

#!/usr/bin/env python3
from sys import argv
from itertools import product
i = {(x,y,0) for y,iy in enumerate(open(argv[1]).read().splitlines()) for x,ix in enumerate(iy) if ix == "#"}
i4 = {(x,y,z,0) for x,y,z in i}
def f(i,m):
ni = set()
da = [x for x in product(*([(-1,0,1)]*m)) if x != (0,)*m]
for p in product(*map(lambda x: range(min(x)-1,max(x)+2), zip(*i))):
n = [tuple(sum(x) for x in zip(p,d)) for d in da]
c = sum(1 for p in n if p in i)
if p in i and 2 <= c <= 3:
ni.add(p)
elif c == 3:
ni.add(p)
return ni
for c in range(6):
i = f(i,3)
i4 = f(i4,4)
print(len(i))
print(len(i4))