advent-of-code/2024/17/main-1.cpp
2024-12-17 21:56:00 -08:00

81 lines
1.1 KiB
C++

#include "../../include/aoc.hpp"
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int ra, rb, rc;
cin.ignore(12);
cin >> ra;
cin.ignore(13);
cin >> rb;
cin.ignore(13);
cin >> rc;
cin.ignore(11);
vector<int> tape;
int n;
while (cin >> n) {
tape.push_back(n);
cin.ignore();
}
vector<int> out;
int p = 0;
while (p < tape.size() - 1) {
int opc = tape[p], opr = tape[p + 1], combo;
switch (opr) {
case 4:
combo = ra;
break;
case 5:
combo = rb;
break;
case 6:
combo = rc;
break;
default:
combo = opr;
}
switch (opc) {
case 0:
ra >>= combo;
break;
case 1:
rb ^= opr;
break;
case 2:
rb = combo & 7;
break;
case 3:
if (ra != 0) {
p = opr;
continue;
}
break;
case 4:
rb ^= rc;
break;
case 5:
out.push_back(combo & 7);
break;
case 6:
rb = ra >> combo;
break;
case 7:
rc = ra >> combo;
break;
}
p += 2;
}
if (out.size() > 0) {
cout << out[0];
for (int i = 1; i < out.size(); i++) {
cout << ',' << out[i];
}
}
cout << '\n';
}