from aoc.input import get_input import copy import itertools import time import collections import re from aoc.partselector import part_one, part_two import functools def pw(line): return line.strip() def p1(): inp = get_input(pw) cube = {} print(inp) ymin = 0 xmin = 0 zmin = 0 ymax = len(inp)-1 xmax = len(inp[0]) - 1 zmax = 0 for y, sample in enumerate(inp): z = 0 for x, v in enumerate(sample): if v == '#': cube[(x, y, z)] = v arround = [(x,y,z) for x in range(-1, 2) for y in range(-1, 2) for z in range(-1, 2)] for _ in range(6): newcube = {} for zi in range(zmin-1, zmax+2): for yi in range(ymin-1, ymax+2): for xi in range(xmin-1, xmax+2): count = 0 for xo, yo, zo in arround: if xo == 0 and yo == 0 and zo == 0: continue if (xi+xo, yi+yo, zi+zo) in cube: #print((xi+xo, yi+yo, zi+zo), '#') count += 1 #print((xi, yi, zi), count) if (xi, yi, zi) in cube: if count in [2,3]: newcube[(xi, yi, zi)] = '#' else: if count == 3: newcube[(xi, yi, zi)] = '#' zmin -= 1 zmax += 1 ymin -= 1 ymax += 1 xmin -= 1 xmax += 1 cube = copy.copy(newcube) print(len(cube)) print(len(cube)) return inp def p2(): inp = get_input(pw) plane = inp cube = set() print(inp) ymin = 0 xmin = 0 zmin = 0 ymax = len(inp)-1 xmax = len(inp[0]) - 1 zmax = 0 wmax = 0 wmin = 0 for y, sample in enumerate(inp): z = 0 for x, v in enumerate(sample): if v == '#': cube.add((x, y, z, 0)) arround = [(x,y,z, w) for x in range(-1, 2) for y in range(-1, 2) for z in range(-1, 2) for w in range(-1, 2)] for _ in range(6): newcube = set() for wi in range(wmin-1, wmax+2): for zi in range(zmin-1, zmax+2): for yi in range(ymin-1, ymax+2): for xi in range(xmin-1, xmax+2): count = 0 for xo, yo, zo, wo in arround: if xo == 0 and yo == 0 and zo == 0 and wo == 0: continue if (xi+xo, yi+yo, zi+zo, wi+wo) in cube: #print((xi+xo, yi+yo, zi+zo), '#') count += 1 #print((xi, yi, zi), count) if (xi, yi, zi, wi) in cube: if count in [2,3]: newcube.add((xi, yi, zi, wi)) else: if count == 3: newcube.add((xi, yi, zi, wi)) wmin -= 1 wmax += 1 zmin -= 1 zmax += 1 ymin -= 1 ymax += 1 xmin -= 1 xmax += 1 cube = copy.copy(newcube) print(len(cube)) print(len(cube)) return inp return 0 result1 = None if part_one(): start = time.time() result1 = p1() print(round(1000*(time.time() - start), 2), 'ms') if part_two(): start = time.time() p2() print(round(1000*(time.time() - start), 2), 'ms')