aboutsummaryrefslogtreecommitdiff
path: root/2024
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-22 10:26:22 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-22 10:27:11 +0100
commitcffdd7d528607f7281fc0a1fed9195e711c1b70f (patch)
tree331b30870d1c3806239d6149da7b18dcdaab400b /2024
parent24ceca020ca7cefc5e0144f87fa3bbc5359b509d (diff)
downloadaoc-cffdd7d528607f7281fc0a1fed9195e711c1b70f.tar.gz
aoc-cffdd7d528607f7281fc0a1fed9195e711c1b70f.zip
Cleanup
Diffstat (limited to '2024')
-rw-r--r--2024/22/day22b.cpp34
1 files changed, 15 insertions, 19 deletions
diff --git a/2024/22/day22b.cpp b/2024/22/day22b.cpp
index 61d4767..4ef41fa 100644
--- a/2024/22/day22b.cpp
+++ b/2024/22/day22b.cpp
@@ -11,9 +11,8 @@
11#include <vector> 11#include <vector>
12using namespace std; 12using namespace std;
13 13
14int64_t Seq(const vector<pair<int, int>>& v, int i) { 14int64_t Seq(int64_t a, int64_t b, int64_t c, int64_t d) {
15 return (v[i-3].second+9) + 19*((v[i-2].second+9) + 15 return (a+9) + 19*((b+9) + 19*((c+9) + 19*(d+9)));
16 19*((v[i-1].second+9) + 19*(v[i].second+9)));
17} 16}
18 17
19int64_t next(int64_t n) { 18int64_t next(int64_t n) {
@@ -26,32 +25,29 @@ int64_t next(int64_t n) {
26 25
27int main() { 26int main() {
28 int64_t s; 27 int64_t s;
29 vector<vector<pair<int, int>>> spc;
30 vector<map<int64_t, int64_t>> tt;
31 map<int64_t, int64_t> sums; 28 map<int64_t, int64_t> sums;
32 set<int64_t> seqs;
33 29
34 for (int i = 0; cin >> s; i++) { 30 for (int i = 0; cin >> s; i++) {
35 spc.push_back(vector<pair<int, int>>()); 31 int64_t a, b, c, d;
36 tt.push_back(map<int64_t, int64_t>()); 32 set<int64_t> tt;
37 33
38 for (int j = 0; j < 2000; j++) { 34 for (int j = 0; j < 2000; j++) {
39 int64_t t = next(s); 35 a = b;
40 spc[i].push_back({t%10, t%10 - s%10}); 36 b = c;
41 s = t; 37 c = d;
38 d = -(s%10);
39 s = next(s);
40 d += s%10;
42 if (j >= 3) { 41 if (j >= 3) {
43 auto k = Seq(spc[i], j); 42 auto k = Seq(a, b, c, d);
44 seqs.insert(k); 43 if (!tt.contains(k)) {
45 if (tt[i].count(k) == 0) 44 tt.insert(k);
46 tt[i][k] = spc[i][j].first; 45 sums[k] += s%10;
46 }
47 } 47 }
48 } 48 }
49 } 49 }
50 50
51 for (unsigned i = 0; i < spc.size(); i++)
52 for (auto [k, v] : tt[i])
53 sums[k] += v;
54
55 auto values = views::values(sums); 51 auto values = views::values(sums);
56 auto best = *max_element(values.begin(), values.end()); 52 auto best = *max_element(values.begin(), values.end());
57 cout << best << endl; 53 cout << best << endl;

Generated with cgit - Back to sebastiano.tronto.net