<jupyter_start><jupyter_text>part 1<jupyter_code>ex = '''.#.
..#
###'''.strip().split('\n')
def process_input(lines):
    z = 0
    active = set()
    for y, line in enumerate(lines):
        for x, c in enumerate(line):
            if c == '#':
                active.add((x, y, z))
    return active
exactive = process_input(ex)
exactive
def count_active_neighbors(pos, active):
    x, y, z = pos
    count = 0
    for i in (x-1, x, x+1):
        for j in (y-1, y, y+1):
            for k in (z-1, z, z+1):
                if (i,j,k) != (x,y,z):
                    if (i,j,k) in active:
                        count += 1
    return count
count_active_neighbors((1,2,0), exactive)
def cycle(active):
    minx = min(r[0] for r in active)
    maxx = max(r[0] for r in active)
    miny = min(r[1] for r in active)
    maxy = max(r[1] for r in active)
    minz = min(r[2] for r in active)
    maxz = max(r[2] for r in active)
    newactive = set()
    for x in range(minx - 1, maxx + 2):
        for y in range(miny - 1, maxy + 2):
            for z in range(minz - 1, maxz + 2):
                c = count_active_neighbors((x, y, z), active)
                if (x, y, z) in active:
                    if (c == 2) or (c == 3):
                        newactive.add((x, y, z))
                else:
                    if c == 3:
                        newactive.add((x, y, z))
    return newactive
cycle(exactive)
excyc = exactive.copy()
for i in range(6):
    excyc = cycle(excyc)
len(excyc)
data = '''....#...
.#..###.
.#.#.###
.#....#.
...#.#.#
#.......
##....#.
.##..#.#'''.strip().split('\n')
data_active = process_input(data)
len(data_active)
datacyc = data_active.copy()
for i in range(6):
    datacyc = cycle(datacyc)
len(datacyc)<jupyter_output><empty_output><jupyter_text>part 2<jupyter_code>def process_input2(lines):
    z = 0
    w = 0
    active = set()
    for y, line in enumerate(lines):
        for x, c in enumerate(line):
            if c == '#':
                active.add((x, y, z, w))
    return active
def count_active_neighbors2(pos, active):
    x, y, z, w = pos
    count = 0
    for i in (x-1, x, x+1):
        for j in (y-1, y, y+1):
            for k in (z-1, z, z+1):
                for l in (w-1, w, w+1):
                    if (i,j,k,l) != (x,y,z,w):
                        if (i,j,k,l) in active:
                            count += 1
    return count
def cycle2(active):
    minx = min(r[0] for r in active)
    maxx = max(r[0] for r in active)
    miny = min(r[1] for r in active)
    maxy = max(r[1] for r in active)
    minz = min(r[2] for r in active)
    maxz = max(r[2] for r in active)
    minw = min(r[3] for r in active)
    maxw = max(r[3] for r in active)
    newactive = set()
    for x in range(minx - 1, maxx + 2):
        for y in range(miny - 1, maxy + 2):
            for z in range(minz - 1, maxz + 2):
                for w in range(minw - 1, maxw + 2):
                    c = count_active_neighbors2((x, y, z, w), active)
                    if (x, y, z, w) in active:
                        if (c == 2) or (c == 3):
                            newactive.add((x, y, z, w))
                    else:
                        if c == 3:
                            newactive.add((x, y, z, w))
    return newactive
def process(lines):
    active = process_input2(lines)
    for i in range(6):
        active = cycle2(active)
    return len(active)
process(ex)
process(data)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1598265895953757, 'fraction_numerical': 0.019942196531791908, 'mean_word_length': 1.621969696969697, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '510044', 'license': 'MIT', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1268, 'n_words': 381, 'path': 'day17.ipynb', 'repo_name': 'g2boojum/AdventOfCode2020', 'size': '3460'}