4 ms·
The way I solved this was by squinting a little and realizing that every time a div instruction happened, then a certain number following it needed to be 0, dep
by yxhuvud 5y ago
The way I solved this was by squinting a little and realizing that every time a div instruction happened, then a certain number following it needed to be 0, depending on the value of certain constants embedded in the code, and also on certain other fields in the input. So instead of starting with an input number, it is possible to calculate the min and max values the fields may contain right there, as long as we embed the field positions in a stack.
As this is only going through the input code once, this is virtually instantaneous and ended up as the day that was fastest of all days to compute.
https://github.com/yxhuvud/aoc21/blob/main/day24.cr https://github.com/yxhuvud/aoc21/blob/main/day24.cr
I guess the solution could be classified as meta-analytical.
- reitzensteinm 5y agoThat's very clever. Though this does rely on the supplied input following a certain format. So far they all seem to. The early out interpreter I describe should work in general, although it will probably fail to accelerate many programs. I saw a lot of reverse engineering of the programs in the AoC subreddit, which was part of the reason I decided to write this up. I didn't even read the supplied program when building this solution.