aboutsummaryrefslogtreecommitdiff
path: root/2024/11/day11a.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/day11a.cpp
parent6cee2c54045d253dc14c808f1e4f25765a675a56 (diff)
downloadaoc-3418444a8da97e5a05f87f9737bed94edd43ec60.tar.gz
aoc-3418444a8da97e5a05f87f9737bed94edd43ec60.zip
Day 11 2024
Diffstat (limited to '2024/11/day11a.cpp')
-rw-r--r--2024/11/day11a.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/2024/11/day11a.cpp b/2024/11/day11a.cpp
new file mode 100644
index 0000000..50c3ebf
--- /dev/null
+++ b/2024/11/day11a.cpp
@@ -0,0 +1,57 @@
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
13pair<uint64_t, uint64_t> split(uint64_t a) {
14 int digits = 0;
15 for (uint64_t b = a; b != 0; b /= 10)
16 digits++;
17
18 if (digits % 2 == 1)
19 return make_pair(0, 0);
20
21 uint64_t j = 1;
22 for (int k = 0; k < digits/2; k++)
23 j *= 10;
24
25 return make_pair(a/j, a%j);
26}
27
28uint64_t count(uint64_t a, int n) {
29 if (n == 0)
30 return 1;
31
32 if (a == 0)
33 return count(1, n-1);
34
35 if (auto [x, y] = split(a); x != 0) {
36 auto c1 = count(x, n-1);
37 auto c2 = count(y, n-1);
38 return c1+c2;
39 }
40
41 return count(a*2024, n-1);
42}
43
44int main() {
45 uint64_t x;
46 vector<uint64_t> old, v;
47 while (cin >> x)
48 v.push_back(x);
49
50 uint64_t tot = 0;
51 for (auto a : v)
52 tot += count(a, 25);
53
54 cout << tot << endl;
55
56 return 0;
57}

Generated with cgit - Back to sebastiano.tronto.net