Skip to content

fredmeews/adventofcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2019

Puzzle 1 - fuel counter upper

fuel_for_module = floor(mass / 3) - 2

Total Fuel Requirements

Individually calculate the fuel needed for the mass of each module (your puzzle input)

Then add together all the fuel values

Inputs

Puzzle 2 - opcodes

CODES MEANINGS

1- ADDS together numbers read from two positions and stores the result in a third position

The three integers immediately after the opcode tell you these three positions
First two - indicate positions from which you should read the input values
Third - indicates the position at which the output should be stored

2- MULTIPLY together numbers read from two positions and stores the result in a third position

99 - program terminating

Once you’re done processing an opcode, move to the next one by stepping forward 4 positions.

Execution

Replace position 1 with the value 12

Replace position 2 with the value 2

RUN

What value is left at position 0 after the program halts?

Part Two - determine what pair of inputs produces the output 19690702

the value placed in address 1 is called the noun

the value placed in address 2 is called the verb.

Each of the two input values will be between 0 and 99, inclusive

Once the program has halted, its output is available at address 0, also just like before. Each time you try a pair of inputs, make sure you first reset the computer’s memory to the values in the program (your puzzle input) - in other words, don’t reuse memory from a previous attempt.

Find the input noun and verb that cause the program to produce the output 19690720. What is 100 * noun + verb? (For example, if noun=12 and verb=2, the answer would be 1202.)

Puzzle 3 - shortest path

Puzzle 4 - password

INPUTS: 235741-706948

Criteria

6 digit number

Within the range given in your puzzle input

Two adjacent digits are the same (like 22 in 122345)

From left to right digits only ever increase or stay the same (like 111123 or 135679)

Puzzle 5 - opcode v2

CODE MEANINGS

3 - STORE takes a single integer as input and saves it to the position given by its only parameter

For example, the instruction 3,50 would take an input value and store it at address 50.

4 - OUTPUT the value of its only parameter

For example, the instruction 4,50 would output the value at address 50

Programs that use these instructions will come with documentation that explains what should be connected to the input and output.

[3,0,4,0,99] outputs whatever it gets as input, then halts

PARAMETER MODES

POSITION MODE (0) - default, param interpreted as position

if the parameter is 50, its value is the value stored at address 50 in memor

IMMEDIATE MODE (1) - param is interpreted as a value

if the parameter is 50, its value is simply 50

EXAMPLE INSTRUCTION - 1002

ABCDE
 1002

DE - two-digit opcode,      02 == opcode 2
 C - mode of 1st parameter,  0 == position mode
 B - mode of 2nd parameter,  1 == immediate mode
 A - mode of 3rd parameter,  0 == position mode,
                                  omitted due to being a leading zero

EXAMPLE WITH PARMETERS - 1002,4,3,4

Multiplies its first two parameters

Param1 = 4, position mode its value is the value stored at address 4 ==> 33

Param2 = 3 in immediate mode, simply has value 3

33 * 3 = 99

Result written according to the third parameter, 4 in position mode

99 is written to address 4 – [1002,4,3,4,99]

NOTES

Parameters that an instruction writes to will never be in immediate mode.

Instruction pointer should increase by the number of values in the instruction after the instruction finishes.

used to be 4, now variable because of the new instructions

Integers can be negative

[1101,100,-1,4,0] is a valid program (find 100 + -1, store the result in position 4).

TEST diagnostic program steps

1. Request from the user the ID of the system to test
Provide it “1”, the ID for the ship’s air conditioner unit
2. Perform a series of diagnostic tests confirming that various parts of the Intcode computer, like parameter modes, function correctly.
For each test, it will run an output instruction indicating how far the result of the test was from the expected value
0 means the test was successfulNon-zero outputs mean that a function is not working correctlycheck the instructions that were run before the output instruction to see which one failed.
3. Output a diagnostic code and immediately halt
This final output isn’t an error; an output followed immediately by a halt means the program finished
If all outputs were zero except the diagnostic code, the diagnostic program ran successfully