Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
set & recursion solution in Clear category for Ulam-Warburton Automaton Hex by kdim
def automaton(step: int, white=set(), black=set(), blue={(0, 0, 0)}) -> int:
if step == 1:
return len(black | blue)
blue_, white_ = set(), set()
for x, y, z in blue:
for dx, dy, dz in ((+1, -1, 0), (+1, 0, -1), (0, +1, -1),
(-1, +1, 0), (-1, 0, +1), (0, -1, +1)):
neighbour = (x + dx, y + dy, z + dz)
if neighbour in black | white:
continue
if neighbour in blue_:
white_.add(neighbour)
blue_.add(neighbour)
return automaton(step - 1, white | white_, black | blue, blue_ - white_)
March 10, 2023
Comments: