September 21, 2023

Solution for Advent of Code 2015 - Day 7: Some Assembly Required

Link to the puzzle text

Part 1

For this part, we need to emulate the computations done by a series of logic gates. We could build an graph of all operations and their operands, but a simple recursive algorithm is enough here. To evaluate a gate, we check if the operands are already evaluated. If they are, we can perform the operation. If not, we evaluate the operands recursively before going back to the top operation. We speed up this process a bit by caching the value of all previously evaluated wires. The start the whole algorithm, we evaluate the only gate we are interested in, a.

Part 2

For part 2, we need to overwrite the value b with the previous answer for a and run the compuation again. We simply delete our cache and add a new entry for b in this fresh cache. After that, we evaluate the gate a again.

Link to my solutions

No comments:

Post a Comment