Advent of Code - 2019 - Day 2

The second problem introduce the Intcode virtual machine, where a sequence of integers should be interpreted as op-codes and arguments. The first version of this machine only does add and mul but I have a feeling this machine will come back in later problems. The first half of the puzzle was trivial, the second half took ages to compute (not to implement). But after I had up:ed the gas limit and split the setup of the Intcode machine memory into setup and initialization it can be run in about 20 seconds on a normal laptop. (Consuming a measly 1503823113 of gas…)

See my solution here - looking forward to seeing other variants would be nice to see if there are more efficient implementations!

I’ve initially stuck to using lists for representing the program, which made the second part run for 10 minutes O_O So after a hint by @hanssv.chain about the efficient use of maps, I rewrote my solution to using maps. That approach paid off and the solution runs in a reasonable amount of time for part 2.

3317798 steps / 2262319426 gas / 150178064 reductions / 7012.12ms