August 26, 2025

Solution for Advent of Code 2018 - Day 16: Chronal Classification

Link to the puzzle text

Part 1

In this puzzle we are given the description of several operations together with testcases and a small program. While the behaviour of each operation is described, the numerical opcode for each operation is unknown. So, we first have to find the mapping by using the testcases as guidance. In part 1, we should count the number of testcases where 3 or more operations fit.
 
We implemented each operation in a similar way. All operations take two inputs and write the result back into a third register, so each operation is just a small lambda function.
 
We then go through each testcase and apply each operation on the input. If the output is the same as the expected output for 3 or more operations, we increase a counter.

Part 2

In part 2, we should execute the provided program and return the result.

For this, we need to figure out the mapping from numerical opcode to operation. We use the testcases from before and look for opcode fitting just a single operation. Once this operation is known, we can remove it as a possibility for each other opcode. This is done in a loop until all opcodes are known. Running the program is then simply executing the right operations after each other.

Link to my solutions

No comments:

Post a Comment