My JavaScript solutions for the Advent Of Code 2019

ApisNecros 2a9ff23498 Begin work on day 15 pt 1 1 week ago
1 581e84a46d Initial commit 11 months ago
11 d72e3a187d Solve day 11 pt 2 2 months ago
12 7c807aa864 Add initial attempt at day 12 pt 2 2 months ago
13 2078d2de47 Add day 13 pt 2 solution 1 week ago
14 e91375d11f Add start to day 14 1 week ago
15 2a9ff23498 Begin work on day 15 pt 1 1 week ago
2 b8229ab5b3 Update input to match challenge 11 months ago
5 d3f6d1fd99 Update computer options 11 months ago
7 df20b425a2 Add day 7 pt II solution 11 months ago
8 99a9864c2c Move SpaceImageFormat to own folder 11 months ago
9 dfa03780c9 Add day 9 part 1 & 2 solutions 10 months ago
IntComp be483cc21f Remove unused function 10 months ago
SpaceImageFormat 99a9864c2c Move SpaceImageFormat to own folder 11 months ago
demos 5123e309b3 Updated program to account for 0! 10 months ago
.eslintrc.json 7bdfbc9533 Disable unused vars warning 11 months ago
.gitignore de0955d9b9 Initial commit 11 months ago
LICENSE e6c82a5837 Update license info 11 months ago
README.md 4f55cde876 Add info about the MODIFY_RELATIVE_BASE opcode 10 months ago
package-lock.json 5dbe341762 Updated package file 1 week ago
package.json d6772b5305 Add UUID module 11 months ago

README.md

AdventOfCode-js-2019

Advent of Code 2019 solutions done in NodeJS

Explanation

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.

Parameter Modes

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.

Position Mode

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.

Immediate Mode

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

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.

Opcode Dictionary

01 - ADD

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

02 - MULTIPLY

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

03 - INPUT

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

04 - OUTPUT

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

05 - JUMP IF TRUE

06 - JUMP IF FALSE

07 - LESS THAN

08 - EQUALS

09 - MODIFY RELATIVE BASE

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

99 - HALT

A simple instruction with no parameters. Stops the computer from running any more instructions.