Demo entry 6719177

Nearest Neighbors

   

Submitted by anonymous on Mar 09, 2018 at 02:22
Language: HTML. Code size: 219 Bytes.

def check_for_life(x, y):
    neighbors = np.sum(grid[x-1:x+2, y-1:y+2]) - grid[x, y]
    if grid[x, y] and not 2 <= neighbors <= 3:
        return 0
    elif neighbors == 3:
        return 1
    return grid[x, y]

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).