My JavaScript solutions for the Advent Of Code 2019
|
1 year ago | |
---|---|---|
1 | 1 year ago | |
2 | 1 year ago | |
5 | 1 year ago | |
7 | 1 year ago | |
IntComp | 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 year 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
.
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 |
A simple instruction with no parameters. Stops the computer from running any more instructions.