aboutsummaryrefslogtreecommitdiff
path: root/2024/22
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-22 09:56:11 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-22 09:56:11 +0100
commit7ec64aaf7c3e0feb3424ef696483f282fbe8f801 (patch)
treee914ff05f45e5608b933432908b94ead795d5c13 /2024/22
parent633104e38f45250289ab245ec16967163b308218 (diff)
downloadaoc-7ec64aaf7c3e0feb3424ef696483f282fbe8f801.tar.gz
aoc-7ec64aaf7c3e0feb3424ef696483f282fbe8f801.zip
Cleaned up day 22 part 2, still slow
Diffstat (limited to '2024/22')
-rw-r--r--2024/22/day22b.cpp35
1 files changed, 6 insertions, 29 deletions
diff --git a/2024/22/day22b.cpp b/2024/22/day22b.cpp
index abd9e6f..5e4e423 100644
--- a/2024/22/day22b.cpp
+++ b/2024/22/day22b.cpp
@@ -11,31 +11,10 @@
11#include <vector> 11#include <vector>
12using namespace std; 12using namespace std;
13 13
14class Seq { 14int64_t Seq(const vector<pair<int, int>>& v, int i) {
15public: 15 return (v[i-3].second+9) + 19*((v[i-2].second+9) +
16 int64_t k; 16 19*((v[i-1].second+9) + 19*(v[i].second+9)));
17 17}
18 Seq() : k{0} {}
19
20 Seq(int kk) : k{kk} {}
21
22 Seq(int64_t a, int64_t b, int64_t c, int64_t d)
23 : k{(a+9)+19*((b+9)+19*((c+9)+19*(d+9)))} {}
24
25 Seq(const vector<pair<int, int>>& v, int i)
26 : Seq(v[i-3].second, v[i-2].second, v[i-1].second, v[i].second) {}
27
28 int64_t operator[](int64_t i) const {
29 int64_t d;
30 for (d = k; i > 0; i--)
31 d /= 19;
32 return (d % 19) - 9;
33 }
34
35 bool step() {
36 return (++k) < 19*19*19*19;
37 }
38};
39 18
40int64_t next(int64_t n) { 19int64_t next(int64_t n) {
41 constexpr int64_t M = 16777216; 20 constexpr int64_t M = 16777216;
@@ -60,7 +39,7 @@ int main() {
60 spc[i].push_back({t%10, t%10 - s%10}); 39 spc[i].push_back({t%10, t%10 - s%10});
61 s = t; 40 s = t;
62 if (j >= 3) { 41 if (j >= 3) {
63 auto k = Seq(spc[i], j).k; 42 auto k = Seq(spc[i], j);
64 seqs.insert(k); 43 seqs.insert(k);
65 if (tt[i].count(k) == 0) 44 if (tt[i].count(k) == 0)
66 tt[i][k] = spc[i][j].first; 45 tt[i][k] = spc[i][j].first;
@@ -68,13 +47,11 @@ int main() {
68 } 47 }
69 } 48 }
70 49
71 Seq seq;
72 int64_t best = 0; 50 int64_t best = 0;
73 for (auto k : seqs) { 51 for (auto k : seqs) {
74 Seq seq(k);
75 int64_t tot = 0; 52 int64_t tot = 0;
76 for (unsigned i = 0; i < spc.size(); i++) 53 for (unsigned i = 0; i < spc.size(); i++)
77 tot += tt[i][seq.k]; 54 tot += tt[i][k];
78 best = max(best, tot); 55 best = max(best, tot);
79 }; 56 };
80 57

Generated with cgit - Back to sebastiano.tronto.net