Compare commits

...

2 commits

Author SHA1 Message Date
eriedaberrie 6edb409e18 2024 day 18 2024-12-17 21:38:52 -08:00
eriedaberrie 1e5b15a387 2024 day 17 2024-12-16 23:48:43 -08:00
3 changed files with 184 additions and 0 deletions

80
2024/17/main-1.cpp Normal file
View file

@ -0,0 +1,80 @@
#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';
}

46
2024/17/main-2.cpp Normal file
View file

@ -0,0 +1,46 @@
#include "../../include/aoc.hpp"
#include <bits/stdc++.h>
using namespace std;
vector<int> 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';
}

58
2024/18/main.cpp Normal file
View file

@ -0,0 +1,58 @@
#include "../../include/aoc.hpp"
#include <bits/stdc++.h>
using namespace std;
unordered_map<icoord, int> m;
const int smax = 70;
void rec(icoord c, int score) {
if (!m.contains(c)) {
return;
}
int &s = m[c];
if (s != -1 && s <= score) {
return;
}
s = score;
score++;
rec(c + icoord(1, 0), score);
rec(c + icoord(-1, 0), score);
rec(c + icoord(0, 1), score);
rec(c + icoord(0, -1), score);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string line;
bool inits[smax + 1][smax + 1] = {};
int i = 0;
while (getline(cin, line) && !line.empty()) {
// NOTE: found part 2 is just binary search on this number until you
// stop getting -1 as output
if (++i > 1024) {
break;
}
istringstream l(line);
int x, y;
l >> x;
l.ignore();
l >> y;
inits[x][y] = true;
}
for (int x = 0; x <= smax; x++) {
for (int y = 0; y <= smax; y++) {
if (!inits[x][y]) {
m[{x, y}] = -1;
}
}
}
rec({0, 0}, 0);
cout << m[{smax, smax}] << '\n';
}