#!/usr/bin/env python # coding: utf-8 # In[1]: import aocd data = aocd.get_data(day=5, year=2017) instructions = list(map(int, data.splitlines())) # In[2]: 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 # In[3]: assert execute([0, 3, 0, 1, -3]) == 5 print("Part 1:", execute(instructions[:])) # In[4]: assert execute([0, 3, 0, 1, -3], True) == 10 print("Part 2:", execute(instructions[:], True))