Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Count cube coordinates solution in Clear category for Ulam-Warburton Automaton Hex by Phil15
from collections import Counter
hex_neighbors = [(0, -1, 1), (0, 1, -1), (-1, 0, 1), (1, 0, -1), (-1, 1, 0), (1, -1, 0)]
def automaton(steps: int) -> int:
hex_cells = set()
if steps > 0:
# https://www.redblobgames.com/grids/hexagons/#coordinates-cube
hex_cells.add((0, 0, 0))
for _ in range(steps - 1):
counts = Counter(
(x + dx, y + dy, z + dz)
for x, y, z in hex_cells
for dx, dy, dz in hex_neighbors
)
hex_cells |= {cell for cell, count in counts.items() if count == 1}
return len(hex_cells)
Feb. 1, 2023
Comments: