Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Cube coordinates solution in Clear category for Ulam-Warburton Automaton Hex by kurosawa4434
from itertools import chain
def automaton(step: int) -> int:
# Cube coordinates
# https://www.redblobgames.com/grids/hexagons/#coordinates
on_cells = new_cells = {(0, 0, 0)}
def adj_cells(q, r, s):
return ((q + dq, r + dr, s + ds) for dq, dr, ds in (
(0, -1, 1), (1, -1, 0), (1, 0, -1), (0, 1, -1), (-1, 1, 0), (-1, 0, 1)))
for _ in range(step - 1):
search_cells = new_cells
new_cells = set()
for q, r, s in set(chain(*(adj_cells(sq, sr, ss) for sq, sr, ss in search_cells))) - on_cells:
if sum((jq, jr, js) in on_cells for jq, jr, js in adj_cells(q, r, s)) == 1:
new_cells.add((q, r, s))
on_cells |= new_cells
return len(on_cells)
Feb. 5, 2023
Comments: