-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday5-1.py
More file actions
38 lines (34 loc) · 971 Bytes
/
Copy pathday5-1.py
File metadata and controls
38 lines (34 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function
#input function for both python2.7 and 3
def getInput(prompt=''):
try:
line = raw_input(prompt)
except NameError:
line = input(prompt)
return line
print('Enter/paste content: Ctrl-D to save. ', end='')
instructions = []
while True:
try:
line = getInput()
except EOFError:
break
instructions.append(line)
instructions = list(map(int, instructions))
def makeMove(instructions, currentStep, jumps):
try:
jumpLen = instructions[currentStep]
nextMove = currentStep + jumpLen
except IndexError:
pass
instructions[currentStep] += 1
jumps += 1
return instructions, nextMove, jumps
goal = len(instructions)
currentStep = 0
jumps = 0
while currentStep < goal:
instructions, currentStep, jumps = makeMove(instructions, currentStep, jumps)
print("jumps:", jumps)