Copyright | (c) Eric Mertens 2019 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
https://adventofcode.com/2019/day/5
This task expands the virtual machine defined in day 2 adding jumps, conditionals, inputs, and outputs.
This solution works with the following passes:
- Parse input text file into a list of numbers
- Execute op codes to extract the input/output "effects"
- Evaluate the effect as a function from a list of inputs to list of outputs
- Apply the function to a single input and find the last output.
>>>
intcodeToList [3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9] <$> [[0],[10]]
[[0],[1]]
>>>
intcodeToList [3,3,1105,-1,9,1101,0,0,12,4,12,99,1] <$> [[0],[10]]
[[0],[1]]
>>>
:{
>>>
intcodeToList
>>>
[3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,
>>>
1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,
>>>
999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99]
>>>
<$> [[7],[8],[9]]
>>>
:}
[[999],[1000],[1001]]