Help for conway.next_generation

Sample CLI

gway conway next-generation

Full Code

def next_generation(board):
    size = len(board)
    def neighbors(r, c):
        return sum(
            board[(r+dr)%size][(c+dc)%size]
            for dr in (-1,0,1) for dc in (-1,0,1)
            if (dr,dc)!=(0,0)
        )
    return [
        [1 if (cell and 2<=neighbors(r,c)<=3) or (not cell and neighbors(r,c)==3) else 0
         for c,cell in enumerate(row)]
        for r,row in enumerate(board)
    ]