Browse Source

Add day 17

master
mid-kid 4 years ago
parent
commit
dce5bb98d8
  1. 25
      d17.py
  2. 8
      d17_input.txt
  3. 2
      d17_output.txt

25
d17.py

@ -0,0 +1,25 @@
#!/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))

8
d17_input.txt

@ -0,0 +1,8 @@
##..####
.###....
#.###.##
#....#..
...#..#.
#.#...##
..#.#.#.
.##...#.

2
d17_output.txt

@ -0,0 +1,2 @@
209
1492
Loading…
Cancel
Save