Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Counter solution in Clear category for Life Counter by gyahun_dash
from collections import Counter
from itertools import chain, product
def life_counter(state, ticks):
cells = product(range(len(state)), range(len(state[0])))
lives = {(y, x) for y, x in cells if state[y][x] == 1}
neighbors = lambda c: set(product(*[(z - 1, z, z + 1) for z in c])) - {c}
for t in range(ticks):
freqs = Counter(chain.from_iterable(map(neighbors, lives)))
lives = {c for c in freqs if freqs[c] in (3 - (c in lives), 3)}
return len(lives)
Sept. 30, 2014
Comments: