2024 day 11

This commit is contained in:
eriedaberrie 2024-12-10 21:27:18 -08:00
parent 23cc0ddc1f
commit 234cade235
2 changed files with 77 additions and 0 deletions

35
2024/11/main-1.cpp Normal file
View file

@ -0,0 +1,35 @@
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
vector<ull> stones;
while (cin >> n) {
stones.push_back(n);
}
for (int i = 0; i < 75; i++) {
for (int x = 0; x < stones.size(); x++) {
if (stones[x] == 0) {
stones[x] = 1;
} else {
int nd = log10(stones[x]) + 1;
if (nd % 2 == 0) {
ull l = pow(10, nd / 2);
stones.insert(stones.begin() + x + 1, stones[x] % l);
stones[x] /= l;
x++;
} else {
stones[x] *= 2024;
}
}
}
}
cout << stones.size() << '\n';
}

42
2024/11/main-2.cpp Normal file
View file

@ -0,0 +1,42 @@
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull getn(int i, ull n) {
static map<pair<int, ull>, ull> m;
if (m.contains({i, n})) {
return m[{i, n}];
}
ull ret;
if (i == 0) {
ret = 1;
} else if (n == 0) {
ret = getn(i - 1, 1);
} else {
int nd = log10(n) + 1;
if (nd % 2 == 0) {
ull l = pow(10, nd / 2);
ret = getn(i - 1, n % l) + getn(i - 1, n / l);
} else {
ret = getn(i - 1, n * 2024);
}
}
m[{i, n}] = ret;
return ret;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
ull ret = 0;
while (cin >> n) {
ret += getn(75, n);
}
cout << ret << '\n';
}