Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
hamming weight (int.bit_count()) solution in Clear category for Ulam–Warburton Automaton by imloafer
def automaton(step: int) -> int:
# your code here
if step == 0:
return 0
return 1 + sum(4 * 3 ** (i.bit_count()-1) for i in range(1, step))
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
assert automaton(6) == 37
assert automaton(7) == 49
print("The mission is done! Click 'Check Solution' to earn rewards!")
Feb. 2, 2023
Comments: