2020/17.py
def part2() -> int:
    """
    Part 2 is the same as part 1, execpt for an added dimension.
    Each of the 6 iterations is O(n^4) where n is the max dimension in any direction.
    """

    actives = set()
    for r in range(len(grid)):
        for c in range(len(grid[0])):
            if grid[r][c]:
                actives.add((r, c, 0, 0))

    for _ in range(6):
        newactives = set(deepcopy(actives))

        minR, maxR = seqminmax(a[0] for a in actives)
        minC, maxC = seqminmax(a[1] for a in actives)
        minZ, maxZ = seqminmax(a[2] for a in actives)
        minA, maxA = seqminmax(a[3] for a in actives)

        for r in range(minR - 1, maxR + 2):
            for c in range(minC - 1, maxC + 2):
                for z in range(minZ - 1, maxZ + 2):
                    for a in range(minA - 1, maxA + 2):
                        cell = (r, c, z, a)
                        count = 0
                        for x in grid_adjs(cell):
                            if x in actives:
                                count += 1

                        if cell not in actives:
                            if count == 3:
                                newactives.add(cell)
                        else:  # the cell is active
                            if count not in (2, 3):
                                newactives.remove(cell)

        actives = newactives

    return len(actives)

    Part 2 is the same as part 1, execpt for an added dimension.
    Each of the 6 iterations is O(n^4) where n is the max dimension in any direction.
    
Part 2 is the same as part 1, execpt for an added dimension.
Each of the 6 iterations is O(n^4) where n is the max dimension in any direction.
Part 2 is the same as part 1 execpt for an added dimension . Each of the 6 iterations is O ( n^4 ) where n is the max dimension in any direction .
def part2() -> int:
    actives = set()
    for r in range(len(grid)):
        for c in range(len(grid[0])):
            if grid[r][c]:
                actives.add((r, c, 0, 0))
    for _ in range(6):
        newactives = set(deepcopy(actives))
        minR, maxR = seqminmax(a[0] for a in actives)
        minC, maxC = seqminmax(a[1] for a in actives)
        minZ, maxZ = seqminmax(a[2] for a in actives)
        minA, maxA = seqminmax(a[3] for a in actives)
        for r in range(minR - 1, maxR + 2):
            for c in range(minC - 1, maxC + 2):
                for z in range(minZ - 1, maxZ + 2):
                    for a in range(minA - 1, maxA + 2):
                        cell = (r, c, z, a)
                        count = 0
                        for x in grid_adjs(cell):
                            if x in actives:
                                count += 1
                        if cell not in actives:
                            if count == 3:
                                newactives.add(cell)
                        else:  
                            if count not in (2, 3):
                                newactives.remove(cell)
        actives = newactives
    return len(actives)
def part2 ( ) -> int : actives = set ( ) for r in range ( len ( grid ) ) : for c in range ( len ( grid [ 0 ] ) ) : if grid [ r ] [ c ] : actives . add ( ( r , c , 0 , 0 ) ) for _ in range ( 6 ) : newactives = set ( deepcopy ( actives ) ) minR , maxR = seqminmax ( a [ 0 ] for a in actives ) minC , maxC = seqminmax ( a [ 1 ] for a in actives ) minZ , maxZ = seqminmax ( a [ 2 ] for a in actives ) minA , maxA = seqminmax ( a [ 3 ] for a in actives ) for r in range ( minR - 1 , maxR + 2 ) : for c in range ( minC - 1 , maxC + 2 ) : for z in range ( minZ - 1 , maxZ + 2 ) : for a in range ( minA - 1 , maxA + 2 ) : cell = ( r , c , z , a ) count = 0 for x in grid_adjs ( cell ) : if x in actives : count += 1 if cell not in actives : if count == 3 : newactives . add ( cell ) else : if count not in ( 2 , 3 ) : newactives . remove ( cell ) actives = newactives return len ( actives )
Part 2 is the same as part 1, execpt for an added dimension.
Part 2 is the same as part 1 execpt for an added dimension .
"""
    Part 2 is the same as part 1, execpt for an added dimension.
    Each of the 6 iterations is O(n^4) where n is the max dimension in any direction.
    """ # the cell is active