Skip to content

Commit 9c6494b

Browse files
authored
Update pyramid_niyazi_cetinkaya.py
1 parent 8346283 commit 9c6494b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Week03/pyramid_niyazi_cetinkaya.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
def calculate_pyramid_height(number_of_blocks: int) -> int:
2-
height = 0
3-
while True:
4-
if number_of_blocks > height*(height+1)/2:
5-
height = height + 1
6-
else:break
7-
return height
1+
def calculate_pyramid_height(number_of_blocks):
2+
height = 0 # Start with height 0
3+
4+
# Loop until blocks required for the next level exceed available blocks
5+
while (height * (height + 1)) // 2 <= number_of_blocks:
6+
height += 1
7+
8+
return height - 1 # Subtract 1 to get the maximum achievable height
89

910

0 commit comments

Comments
 (0)