Skip to content

Instantly share code, notes, and snippets.

@LaBlazer
Created March 10, 2020 00:37
Show Gist options
  • Save LaBlazer/7fe250875835b6571d655a0b557dc774 to your computer and use it in GitHub Desktop.
Save LaBlazer/7fe250875835b6571d655a0b557dc774 to your computer and use it in GitHub Desktop.
def sum_tree(w, h):
summ = 0
for i in range(0, h + 1):
print(f"{summ} + {w**i}")
summ += w**i
return summ
def formula_tree(w, h):
return (w**(h + 1) - 1) // (w - 1)
w = 3
h = 4
print(f"Sum: {sum_tree(w, h)}")
print(f"Formula: {formula_tree(w, h)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment