day 09
sensor boost
approach
this is the day the interpreter moves into its own intcode.py. memory becomes a defaultdict(int), so reads and writes past the end of the program just work. get_args turns every parameter into an address according to its mode (position, immediate or relative to base), so each opcode reads ic[args[i]] the same way. opcode 9 adjusts the relative base.
ip is advanced before the opcode runs, so the jumps can simply overwrite it. sol.py runs the program with input 1 for part 1 and 2 for part 2 and prints every output.
the trick
resolving every parameter to an address, even immediate ones, means the opcodes never deal with modes.
python
def get_args(ic,modes,size,ip,base):
args=[]
for i in range(1,size):
if modes[i-1]==0:
args.append(ic[ip+i])
elif modes[i-1]==1:
args.append(ip+i)
else:
args.append(ic[ip+i]+base)
return args