Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
14-liner: easily up to 10**100 solution in Speedy category for Ulam–Warburton Automaton by przemyslaw.daniel
from math import comb
from itertools import zip_longest
def automaton(steps: int) -> int:
result, shift = [], 0
for bit in range(steps.bit_length() - 1, -1, -1):
if steps & (1 << bit):
result += [[0]*shift + [comb(bit, x) for x in range(bit + 1)]]
shift += 1
result = [sum(c) for c in zip_longest(*result, fillvalue=0)]
result = sum(count*3**value for value, count in enumerate(result))
return max(0, (4 * result - 1) // 3)
Feb. 3, 2023
Comments: