aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

day11a.cpp (898B)


      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>
     11 using namespace std;
     12 
     13 pair<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 
     28 uint64_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 
     44 int 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 }