Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Brute force solution in Clear category for Ulam–Warburton Automaton by rybld2
def hamming(n):
"""counts the number of 1’s in the binary expansion of n"""
return str(bin(n)).count('1')
def automaton(step: int) -> int:
"""Let u(n) denote the number of on cells at the n th stage. u(0) = 0, u(1) = 1 and for n ≥ 2.
u(n) = 4/3*3^wt(n−1)where wt(n) is the Hamming weight function which counts the number of 1’s in
the binary expansion of n
Let U(n) denote the total number of on cells after n stages.
U(n) = sum(u(i)for i in range(n))
see:
https://arxiv.org/pdf/1901.10565.pdf
"""
if step in {0, 1}: return step
return int(sum((4 / 3 * 3 ** hamming(i)) for i in range(step)))
Feb. 1, 2023
Comments: