aboutsummaryrefslogtreecommitdiff
path: root/2024/11/day11b.cpp
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-11 07:03:12 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-11 07:03:12 +0100
commit3418444a8da97e5a05f87f9737bed94edd43ec60 (patch)
treeb3ba5bd74f18179be287f367f70934b08fb29a15 /2024/11/day11b.cpp
parent6cee2c54045d253dc14c808f1e4f25765a675a56 (diff)
downloadaoc-3418444a8da97e5a05f87f9737bed94edd43ec60.tar.gz
aoc-3418444a8da97e5a05f87f9737bed94edd43ec60.zip
Day 11 2024
Diffstat (limited to '')
-rw-r--r--2024/11/day11b.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/2024/11/day11b.cpp b/2024/11/day11b.cpp
new file mode 100644
index 0000000..7f78e8e
--- /dev/null
+++ b/2024/11/day11b.cpp
@@ -0,0 +1,62 @@
1#include <algorithm>
2#include <cstdint>
3#include <iostream>
4#include <map>
5#include <ranges>
6#include <set>
7#include <sstream>
8#include <string>
9#include <string_view>
10#include <vector>
11using namespace std;
12
13map<pair<uint64_t, uint64_t>, uint64_t> t;
14
15pair<uint64_t, uint64_t> split(uint64_t a) {
16 int digits = 0;
17 for (uint64_t b = a; b != 0; b /= 10)
18 digits++;
19
20 if (digits % 2 == 1)
21 return make_pair(0, 0);
22
23 uint64_t j = 1;
24 for (int k = 0; k < digits/2; k++)
25 j *= 10;
26
27 return make_pair(a/j, a%j);
28}
29
30uint64_t count(uint64_t a, int n) {
31 if (n == 0)
32 return 1;
33
34 if (auto it = t.find(make_pair(a, n)); it != t.end())
35 return it->second;
36
37 if (a == 0)
38 return t[make_pair(a, n)] = count(1, n-1);
39
40 if (auto [x, y] = split(a); x != 0) {
41 auto c1 = count(x, n-1);
42 auto c2 = count(y, n-1);
43 return t[make_pair(a, n)] = c1+c2;
44 }
45
46 return t[make_pair(a, n)] = count(a*2024, n-1);
47}
48
49int main() {
50 uint64_t x;
51 vector<uint64_t> old, v;
52 while (cin >> x)
53 v.push_back(x);
54
55 uint64_t tot = 0;
56 for (auto a : v)
57 tot += count(a, 75);
58
59 cout << tot << endl;
60
61 return 0;
62}

Generated with cgit - Back to sebastiano.tronto.net