Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
formula solution in Clear category for Toothpicks by kdim
# https://www.youtube.com/watch?v=_UtCli1SgjI
# at the 7th minute of the video the formula is shown
import math
def toothpicks(step: int) -> int:
k = int(math.log2(step))
i = step - 2 ** k
if not i:
return (2 ** (2 * k + 1) + 1) / 3
else:
return toothpicks(2 ** k) + 2 * toothpicks(i) + toothpicks(i + 1) - 1
March 8, 2023
Comments: