My JavaScript solutions for the Advent Of Code 2019
ApisNecros 2a9ff23498 Begin work on day 15 pt 1 | 1 month ago | |
---|---|---|
1 | 1 year ago | |
11 | 3 months ago | |
12 | 3 months ago | |
13 | 1 month ago | |
14 | 1 month ago | |
15 | 1 month ago | |
2 | 1 year ago | |
5 | 1 year ago | |
7 | 1 year ago | |
8 | 1 year ago | |
9 | 1 year ago | |
IntComp | 1 year ago | |
SpaceImageFormat | 1 year ago | |
demos | 1 year ago | |
.eslintrc.json | 1 year ago | |
.gitignore | 1 year ago | |
LICENSE | 1 year ago | |
README.md | 1 year ago | |
package-lock.json | 1 month ago | |
package.json | 1 year ago |
Advent of Code 2019 solutions done in NodeJS
A big theme of this year's challenge is an Intcode Computer the user is tasked with designing. This computer works on programs from a tape, or stack, of integers. Some of these integers on the stack are instructions, or opcodes. Opcodes are 2-digit integers (assumed 0 prefixed) that represent actions for the computer to perform on the stack. All integers on the stack are represented as decimal numbers.
The Intcode Computer being built has two Parameter Modes: Position Mode, and Immediate Mode. Each opcode can self-describe the Parameter Mode to use for each of its parameters independent of each other.
In Position Mode, the computer's default setting, parameters passed to functions are considered to be addresses where the actual value to operate on can be found. Thus, in Position Mode, an input of 42
tells the computer to look at memory address 42 on the stack.
In Immediate Mode, the parameter is taken "as is", and operated on accordingly. For example, 42
in Immediate Mode is treated as 42
.
Relative mode acts similarly to Position Mode, where the final value is retrieved from another location in memory. It's different, though, in that a "Relative Base Offset" is added to that memory address to get the true address. The Relative Base Offset value is tracked by the computer's memory stack.
Add two numbers, and outputs to the memory address in the third parameter. Opcode accepts 2 Postion Mode markers.
Forms | Description |
---|---|
1 | Add two values in Position Mode |
01 | Add two values in Position Mode |
101 | Add two values. First in Immediate Mode, second in Position Mode |
001 | Add two values in Position Mode |
1001 | Add two values. First in Position Mode, second in Immediate Mode |
1101 | Add two values in Position Mode |
Parameters | Description |
---|---|
Operand 1 | First number, or address of the number, to add |
Operand 2 | Second number, or address of the number, to add |
Output position | The memory address to store the result in |
Multiply two numbers, and outputs to the memory address in the third parameter. Opcode accepts 2 Postion Mode markers.
Forms | Description |
---|---|
2 | Multiply two values in Position Mode |
02 | Multiply two values in Position Mode |
102 | Multiply two values. First in Immediate Mode, second in Position Mode |
002 | Multiply two values in Position Mode |
1002 | Multiply two values. First in Position Mode, second in Immediate Mode |
1102 | Multiply two values in Position Mode |
Parameters | Description |
---|---|
Operand 1 | First number, or address of the number, to multiply |
Operand 2 | Second number, or address of the number, to multiply |
Output position | The memory address to store the result in |
Takes input from either the runtime input array, or from the console, depending on the Input Mode Map. The Input Mode Map is an array of value, either INPUT_FROM_CONSOLE
or INPUT_FROM_RUNTIME_STACK
, provided to the computer before running. Each time an INPUT opcode is encounter, an Input Mode is shifted off of this array. Once the array is empty, any further INPUT opcodes encounter will assume INPUT_FROM_RUNTIME_STACK
unless the inputFromConsole
option is true.
If the input is set to come from the runtime input array, and the array is empty, the computer will pause execution until either the Run
function for the Input
functions are called on the computer.
The output position may be in either Immediate Mode or Relative Mode.
Forms | Description |
---|---|
3 | Receive input |
03 | Receive input |
103 | Receive input in Immediate Mode |
203 | Receive input in Relative Mode |
Parameters | Description |
---|---|
Output position | The memory address to store the result in |
Outputs either a value from a memory address, or a literal value. This output is initially sent to an outputValues
array. If the computer's outputToConsole
option is true, then the output is instead displayed in the console.
If the computer has an outputComputer
set, then the output is instead sent to the output computer through an Input
call to that computer.
Forms | Description |
---|---|
4 | Output a value in Position Mode |
04 | Output a value in Position Mode |
104 | Output a value in Immediate Mode |
Parameters | Description |
---|---|
Operand 1 | The number, or memory address of the number, to output |
Takes one parameter as input, and adds that number to the stack's Relative Base Offset. This value may be either a positive or negative integer.
Parameters | Description |
---|---|
Operand 1 | The number, or memory address of the number, to add to the Relative Base Offset |
A simple instruction with no parameters. Stops the computer from running any more instructions.