Main thread for Day 17 of the 2024 advent of code. Feel free to discuss the challenge and ask questions. If particular discussions become large, we can break them off into new threads.
Some Rules:
Please try to keep spoilers within spoiler tags. This is done by typing [spoiler]text to be blurred[\spoiler]. If you have longer sections you can also use the [details=“Title”] tags.
Some reading comprehension issues, again, but then it’s just a simple implement-the-spec task in part1. Part2 relies on observing that the code iterates through 1 3-bit piece of the input at a time, and reverse-engineers the full code by iteratively simulating candidates.
Finally got around to this. I seem to have taken a very similar approach to @p88h; not sure, I’m super happy with part 2 because it forces you to make several assumptions about the input that (at least to me) are not clear from the description. For details on the assumptions, see the comments on the solve function.
Day 17 was a lot harder than the previous entries and since it took more work, I figured I might as well share my solution for part 2… I adapted parsing code from @erikwastaken for this cleaned up version as my original didn’t have any parsing (just copy&pasted the input into code).
I wrote a lot of experiment code trying to work out any patterns in how the output changes with register A. Eventually figured out how to output the last byte of the input program, that A is processed 3 bits at a time, and that the last outputs depend only on the higher bits of A. Thus it was possible to reconstruct the output program in reverse. Not sure if my queue based algorithm is “good” in an objective sense but it was pretty fast and got the job done.
I think my solving process would’ve been easier had I written out the input program into code manually to analyze it better instead of guessing from outputs.