#!/bin/python3 import sys from pprint import pprint input_f = sys.argv[1] ######################################### # # # Part 1 # # # ######################################### lines = [] with open(input_f) as file: for line in file: lines.append(int(line.rstrip())) curr = 0 tmp = 0 prev = 0 steps=0 while curr <= len(lines)-1: steps+=1 #print('Start:',lines) #print('Starting at index',curr,'value',lines[curr]) prev = curr if curr+lines[curr] > len(lines)-1: break #print('Jumps from [',curr,'] =',lines[curr],'to ',end='') curr = lines[curr]+curr #print('[',curr,'] =',lines[curr]) #print('Increment',lines[prev],end=' ') lines[prev] += 1 #print('to',lines[prev]) #print('End:',lines,'curr=',curr) #input() print(steps) ######################################### # # # Part 2 # # # ######################################### lines = [] with open(input_f) as file: for line in file: lines.append(int(line.rstrip())) curr = 0 tmp = 0 prev = 0 steps=0 while curr <= len(lines)-1: steps+=1 #print('Start:',lines) #print('Starting at index',curr,'value',lines[curr]) prev = curr if curr+lines[curr] > len(lines)-1: break #print('Jumps from [',curr,'] =',lines[curr],'to ',end='') curr = lines[curr]+curr #print('[',curr,'] =',lines[curr]) offset = lines[prev] #abs((lines[prev])-(lines[curr])) #print('Offset:',offset) if offset >= 3: #print('Decrease',lines[prev],end=' ') lines[prev] -= 1 else: #print('Increase',lines[prev],end=' ') lines[prev] += 1 #print('to',lines[prev]) #print('End:',lines,'curr=',curr) #input() print(steps)