Skip to content

Commit b213494

Browse files
authored
Create pyramid_Sevval_Ok.py
1 parent 71f5b39 commit b213494

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Week03/eek03/pyramid_Sevval_Ok.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def calculate_pyramid_height(number_of_blocks: int) -> int:
2+
3+
if number_of_blocks <= 0:
4+
return 0
5+
6+
height = 0
7+
used = 0
8+
9+
while True:
10+
next_level = height + 1
11+
if used + next_level > number_of_blocks:
12+
break
13+
used += next_level
14+
height += 1
15+
16+
return height
17+
18+
if __name__ == "__main__":
19+
tests = [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 15]
20+
for n in tests:
21+
print(n, "->", calculate_pyramid_height(n))

0 commit comments

Comments
 (0)