hackerrank jumping on the clouds code example
Example: hackerrank jumping on the clouds
# https://www.hackerrank.com/challenges/jumping-on-the-clouds
# This is my solution to this fun challenge
def jumpingOnClouds(c):
len_c = len(c)
counter = 0
result = 0
print('c[]:', c)
while counter < len_c:
# for debugging purpose check these print statements
if counter + 2 < len_c:
print("current:", c[counter], "Two ahead:", c[counter+2], "counter:", counter,"result: ", result)
else:
print("current:", c[counter], "counter:", counter,"result: ", result)
# jump ahead as long as it's safe 2 steps ahead or unsafe 1 spot next
if counter + 2 < len_c and c[counter+2] == 0:
counter = counter + 2
result = result + 1
continue
elif counter + 1 < len_c and c[counter+1] == 0:
counter = counter + 1
result = result + 1
continue
elif counter + 1 < len_c and c[counter+1] == 1:
counter = counter + 2
result = result + 1
continue
counter = counter + 1
print("result: ", result)
return result