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 mortonfox
def wt(n):
return bin(n).count('1')
def u(n):
return 1 if n == 1 else 4 * 3 ** (wt(n - 1) - 1)
def automaton(step: int) -> int:
return sum(map(u, range(1, step+1)))
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!")
Feb. 6, 2023