r/adventofcode • • Dec 21 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 21 Solutions -🎄-

--- Day 21: Chronal Conversion ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code: The Party Game!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 21

Transcript:

I, for one, welcome our new ___ overlords!


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked at 01:01:01! XD

9 Upvotes

93 comments sorted by

View all comments

Show parent comment

1

u/wlandry Dec 21 '18

I uploaded a buggy version :( Here is a fixed version of the core logic.

while(true)
  {
    apply_op(registers, instructions[registers[ip]]);
    ++registers[ip];
    if(registers[ip] == 28)
      {
        if(stopping_values.find(registers[5]) == stopping_values.end())
          {
            if(stopping_values.empty())
              {
                std::cout << "Part 1: " << registers[5] << "\n";
              }
            stopping_values.insert(registers[5]);
            last_stop = registers[5];
          }
        else
          {
            break;
          }
      }
  }
std::cout << "Part 2: " << last_stop << "\n";