AoC 2024 Day 17: Virtual Machininator

Source: Day 17: Chronospatial Computer

Full solution for today (spoilers!).

Part 1

Implement a virtual machine. The machine will have 3 unbounded signed registers, 8 opcodes (see below), a variable parameter scheme (see below that). You will be given the initial values of the 3 registers and a program. Find the final output.

Instructions

OpcodeInstructionDescriptionNotes
0adv reg/valA = A >> OP
1bxl valB = B ^ OP
2bst reg/valB = OP & 0b111
3jnz valIf a =/= 0, jump to LIT
4bxc ignoreB = B ^ CStill takes param, but ignores it
5out reg/valOutput bOnly outputs lowest 3 bits
6bdv reg/valB = A >> OPSame as adv but writes to b
7cdv reg/valC = A >> OPSame as adv but writes to c

Parameter specification

For instructions that can take reg/val, 0 to 3 (inclusive) are treated as literal values, 4 is register A, 5 is B, 6, is C, and 7 is an error (should never happen).

For instructions that only take val, it’s always a literal value in the range 0 to 7 (inclusive).

read more...


AoC 2022 Day 11: Monkeyinator

Source: Monkey in the Middle

Part 1

Simulate a collection of ‘monkeys’. Each monkey will have a number of items which it will then apply a mathematical operation to, then always divide by 3, then test divisibility to pass to one of two other monkeys. Return as answer the product of the two highest number of times a monkey applies it’s main function to individual items after 20 steps.

Note: Monkeys will always be evaluated in order (so monkey 1 will evaluate any items passed by monkey 0 again in the same round).

read more...