My JavaScript solutions for the Advent Of Code 2019

ApisNecros d3f6d1fd99 Update computer options 1 năm trước cách đây
1 581e84a46d Initial commit 1 năm trước cách đây
2 9696c4f8ca Update retrieval of 0th index 1 năm trước cách đây
5 d3f6d1fd99 Update computer options 1 năm trước cách đây
7 df20b425a2 Add day 7 pt II solution 1 năm trước cách đây
IntComp 2a18ce4704 DeepClone initial memory on Reset 1 năm trước cách đây
.eslintrc.json 7bdfbc9533 Disable unused vars warning 1 năm trước cách đây
.gitignore de0955d9b9 Initial commit 1 năm trước cách đây
LICENSE e6c82a5837 Update license info 1 năm trước cách đây
README.md 5dd6795529 Add explanation & start opcode dictionary 1 năm trước cách đây
package-lock.json d6772b5305 Add UUID module 1 năm trước cách đây
package.json d6772b5305 Add UUID module 1 năm trước cách đây

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.

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

04 - OUTPUT

05 - JUMP IF TRUE

06 - JUMP IF FALSE

07 - LESS THAN

08 - EQUALS

99 - HALT

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