Advent of Code - Day 21

I solved it in a very similar fashion as 19. I detected whenever the loop started and then I jumped to the end of the loop:

  defp compute(1, instructions, {0, 18, _, 0, r4, r5}) do
    r2 = div(r5, 256)
    r3 = r2 + 1
    compute(1, instructions, {0, 19, r2, r3, r4, r5})
  end

Then every time we reached instruction 28, I stored the value we were supposed to compare against, and continued as usual. Once the value to be compared on instruction 28 repeats, the previous value is the solution.

This is the first time I actually did not enjoy the puzzle. There was basically no coding and mostly debugging. :frowning:

3 Likes