I’m starting to doubt my abilities as a programmer as more and more of the problems’ second parts are winning over me.
I reused most of the code I did in problem number 16 for this problem. It helped a lot for the first part of the problem. The only difference is that I set the instruction pointer to the correct register before starting the execution of the program.
This worked well for the first part of the problem, but the simple change of starting with
[1, 0, 0, 0, 0, 0] instead of
[0, 0, 0, 0, 0, 0] for the second part made my program take a lot longer to execute. After a couple of vain attempts at optimization, I decided to go look on the advent subreddit, I found out most people reverse engineered their code into a simpler format.
After watching the register during the execution and the code for my program, I started out with this code:
But even this took a while to compute, so I analyzed the inner loop a bit more and found out it’s just checking if there is a factor of
r1/r2 and adds it to
r0. I simplified the code to this and found my solution with it:
Finding the solution helped me regain a little confidence that I can solve the other problems I skipped previously with some similar work.