Skip to content

Commit bedc416

Browse files
authored
Merge pull request larissalages#39 from Diegoslourenco/master
Create jumping_on_cloudds.py in hackerhank folder
2 parents 3ff1f5c + 4235593 commit bedc416

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
80.2 KB
Loading
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def main():
2+
#test case, the answer must be 4
3+
c = [ 0, 0, 1, 0, 0, 1, 0 ]
4+
5+
print(jumpingOnClouds(c))
6+
7+
return
8+
9+
def jumpingOnClouds(c):
10+
11+
# Counting the jumps
12+
jumps = 0
13+
i = 0
14+
15+
while (i < len(c) - 1):
16+
if i == len(c) - 1:
17+
break
18+
elif c[i+2] == 0: # if there is a zero two indix away, you can jump
19+
jumps += 1
20+
i += 1 # You are skipping one index
21+
else:
22+
jumps += 1
23+
24+
i += 1 # Each turn you go to the next index
25+
26+
return jumps
27+
28+
main()

0 commit comments

Comments
 (0)