From dce5bb98d8351a1dcaa4c8deb351d75694b293ea Mon Sep 17 00:00:00 2001 From: mid-kid Date: Thu, 17 Dec 2020 16:23:41 +0100 Subject: [PATCH] Add day 17 --- d17.py | 25 +++++++++++++++++++++++++ d17_input.txt | 8 ++++++++ d17_output.txt | 2 ++ 3 files changed, 35 insertions(+) create mode 100755 d17.py create mode 100644 d17_input.txt create mode 100644 d17_output.txt diff --git a/d17.py b/d17.py new file mode 100755 index 0000000..72c4270 --- /dev/null +++ b/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)) diff --git a/d17_input.txt b/d17_input.txt new file mode 100644 index 0000000..2869685 --- /dev/null +++ b/d17_input.txt @@ -0,0 +1,8 @@ +##..#### +.###.... +#.###.## +#....#.. +...#..#. +#.#...## +..#.#.#. +.##...#. diff --git a/d17_output.txt b/d17_output.txt new file mode 100644 index 0000000..7082f92 --- /dev/null +++ b/d17_output.txt @@ -0,0 +1,2 @@ +209 +1492