From 234cade235beebb462906f09b313951884259928 Mon Sep 17 00:00:00 2001 From: eriedaberrie Date: Tue, 10 Dec 2024 21:27:18 -0800 Subject: [PATCH] 2024 day 11 --- 2024/11/main-1.cpp | 35 +++++++++++++++++++++++++++++++++++ 2024/11/main-2.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 2024/11/main-1.cpp create mode 100644 2024/11/main-2.cpp diff --git a/2024/11/main-1.cpp b/2024/11/main-1.cpp new file mode 100644 index 0000000..6392c6d --- /dev/null +++ b/2024/11/main-1.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + +typedef unsigned long long ull; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int n; + vector 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'; +} diff --git a/2024/11/main-2.cpp b/2024/11/main-2.cpp new file mode 100644 index 0000000..4e6ecd5 --- /dev/null +++ b/2024/11/main-2.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; + +typedef unsigned long long ull; + +ull getn(int i, ull n) { + static map, 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'; +}