First I have translated the input into "assembler" using the disassembler I did for day 19, and then I reassembled the solution into C++.
In the code, the program exits when register 5 is equal to register 0.
So I've added the code to check those two conditions.
#include <iostream> #include <set> using namespace std; int main() { set<int> seen; int last_r5 = 0; int r0, r1, r3, r4, r5; l6: r1 = r5 | 65536; r5 = 10678677; l8: r4 = r1 & 255; r5 += r4; r5 &= 16777215; r5 *= 65899; r5 &= 16777215; if (256 > r1) goto l28; r4 = 0; l18: r3 = r4 + 1; r3 *= 256; if (r3 > r1) goto l26; r4 += 1; goto l18; l26: r1 = r4; goto l8; l28: if (last_r5 == 0) { cout << "Part1: " << r5 << endl; } if (seen.find(r5) == seen.end()) { seen.insert(r5); last_r5 = r5; } else { cout << "Part2: " << last_r5 << endl; return 0; } goto l6; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
First I have translated the input into "assembler" using the disassembler I did for day 19, and then I reassembled the solution into C++.
In the code, the program exits when register 5 is equal to register 0.
So I've added the code to check those two conditions.