Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Ulam–Warburton Automaton by freeman_lex
def automaton(step: int) -> int:
neib = {}
filled = set()
to_fill = {(0, 0)}
for _ in range(step):
filled |= to_fill
for x, y in to_fill:
for dx, dy in ((0, 1), (0, -1), (-1, 0), (1, 0)):
x1, y1 = x + dx, y + dy
neib[(x1, y1)] = neib.get((x1, y1), 0) + 1
to_fill = {k for k, v in neib.items() if v == 1} - filled
return len(filled)
print("Example:")
print(automaton(2))
# These "asserts" are used for self-checking
assert automaton(1) == 1
assert automaton(2) == 5
assert automaton(3) == 9
assert automaton(4) == 21
assert automaton(5) == 25
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 30, 2023