19. A thief trying to escape from jail. He has to cross N walls each with varying heights (every height is greater than 0). He climbs X feet every time. But, due to the slippery nature of those walls, every time he slips back by Y feet. Now the task is to calculate the total number of jumps required to cross all walls and escape from the jail.
# Python program to find the number of
# jumps required
# function to calculate jumps required to
# cross walls
def jumpcount(x, y, n, height):
jumps = 0
for i in range(n):
if (height[i] <= x):
jumps += 1
continue
""" If height of wall is greater than
up move """
h = height[i]
while (h > x):
jumps += 1
h = h - (x - y)
jumps += 1
return jumps
x = 10
y = 1
height = [ 11, 10, 10, 9 ]
n = len(height)
print (jumpcount(x, y, n, height))
Comments
Leave a comment