Created
March 10, 2020 00:37
-
-
Save LaBlazer/7fe250875835b6571d655a0b557dc774 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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