diff --git a/2024/17/main-1.cpp b/2024/17/main-1.cpp new file mode 100644 index 0000000..85c4859 --- /dev/null +++ b/2024/17/main-1.cpp @@ -0,0 +1,80 @@ +#include "../../include/aoc.hpp" +#include +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 tape; + int n; + while (cin >> n) { + tape.push_back(n); + cin.ignore(); + } + + vector 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'; +} diff --git a/2024/17/main-2.cpp b/2024/17/main-2.cpp new file mode 100644 index 0000000..e0b56f2 --- /dev/null +++ b/2024/17/main-2.cpp @@ -0,0 +1,46 @@ +#include "../../include/aoc.hpp" +#include +using namespace std; + +vector tape; + +// HACK: hardcoded input +ll rec(int i, ll a) { + for (ll aa = a << 3; aa < (a + 1) << 3; aa++) { + ll b = aa & 7; + b ^= 1; + ll c = aa >> b; + b ^= c ^ 4; + if ((b & 7) == tape[i]) { + if (i == 0) { + return aa; + } else { + ll n = rec(i - 1, aa); + if (n != -1) { + return n; + } + } + } + } + return -1; +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int n; + cin.ignore(12); + cin >> n; + cin.ignore(13); + cin >> n; + cin.ignore(13); + cin >> n; + cin.ignore(11); + while (cin >> n) { + tape.push_back(n); + cin.ignore(); + } + + cout << rec(tape.size() - 1, 0) << '\n'; +}