29 lines
322 B
Python
29 lines
322 B
Python
with open('data05.txt') as f:
|
|
data = f.readlines()
|
|
|
|
jumps = list(map(int, data))
|
|
steps = 0
|
|
i = 0
|
|
|
|
'''
|
|
# part 1
|
|
while i < len(jumps):
|
|
old = i
|
|
i += jumps[i]
|
|
jumps[old] += 1
|
|
steps += 1
|
|
'''
|
|
|
|
# part 2
|
|
while i < len(jumps):
|
|
j = jumps[i]
|
|
if j > 2:
|
|
jumps[i] -= 1
|
|
else:
|
|
jumps[i] += 1
|
|
i += j
|
|
steps += 1
|
|
|
|
|
|
print(steps)
|