import aocd
data = aocd.get_data(day=5, year=2017)
instructions = list(map(int, data.splitlines()))
def execute(instructions, decrement_at_3=False):
pos = 0
steps = 0
while 0 <= pos < len(instructions):
delta = instructions[pos]
if (not decrement_at_3) or delta < 3:
instructions[pos] += 1
else:
instructions[pos] -= 1
pos += delta
steps += 1
return steps
assert execute([0, 3, 0, 1, -3]) == 5
print("Part 1:", execute(instructions[:]))
Part 1: 372671
assert execute([0, 3, 0, 1, -3], True) == 10
print("Part 2:", execute(instructions[:], True))
Part 2: 25608480