Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
A recursive automaton solution in Clear category for Ulam–Warburton Automaton by Tinus_Trotyl
def automaton(step: int) -> int:
def stepper(last, step):
nonlocal coords
if step > 1:
new = []
for x0, y0 in last:
for dx, dy in dirs:
x, y = x0 + dx, y0 + dy
if (x, y) not in coords:
if len([cs for r, s in dirs if (cs := (x + r, y + s)) in coords]) == 1:
new.append((x, y))
coords += new
stepper(new, step - 1)
return
dirs = ((1, 0), (0, 1), (-1, 0), (0, -1))
coords = [(0, 0)]
stepper(coords, step)
return len(coords)
Feb. 15, 2023