July 19, 2024

Solution for Advent of Code 2016 - Day 23: Safe Cracking

Link to the puzzle text

Part 1

In this puzzle we have the same pseudo-assembly as in day 12. A new opcode "tgl" is added. This opcode modifies the source code itself by switching an opcode specified by an offset. We are again given a program and asked to find the output for a given input number.

We reused the answer from day 12 and implemented the new opcode. For speeding up the execution, we also replaced the regex run every cycle with a simple string splitting and comparison. This was enough to get the answer for part 1.

Part 2

For part 2, we are given a different input for the program and are again asked for the output. Simply running the program took to long, so a different approach was needed. Slowly increasing the input number yielded a sequence which was recognized as a factorial with a constant on top. This way we could give an explicit formula. Since the exact constant probably varies from input to input, we calculate it from the answer of part 1.

Link to my solutions

No comments:

Post a Comment