diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-22 08:54:33 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-22 08:54:33 +0100 |
| commit | 633104e38f45250289ab245ec16967163b308218 (patch) | |
| tree | 5cb43a1ef46b84289969e31a1486e2cdfd40f67f /2024 | |
| parent | 6cbc9b03a74bcb295271de36256318d6945a2963 (diff) | |
| download | aoc-633104e38f45250289ab245ec16967163b308218.tar.gz aoc-633104e38f45250289ab245ec16967163b308218.zip | |
Day 22 2024, but it's slow
Diffstat (limited to '2024')
| -rw-r--r-- | 2024/22/Makefile | 11 | ||||
| -rw-r--r-- | 2024/22/day22a.cpp | 32 | ||||
| -rw-r--r-- | 2024/22/day22b.cpp | 84 |
3 files changed, 127 insertions, 0 deletions
diff --git a/2024/22/Makefile b/2024/22/Makefile new file mode 100644 index 0000000..d2a55c5 --- /dev/null +++ b/2024/22/Makefile | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | CC=g++ -std=c++20 -g -Wall | ||
| 2 | |||
| 3 | a: | ||
| 4 | ${CC} -o a.out day22a.cpp | ||
| 5 | ./a.out | ||
| 6 | |||
| 7 | b: | ||
| 8 | ${CC} -o b.out day22b.cpp | ||
| 9 | ./b.out | ||
| 10 | |||
| 11 | .PHONY: a b | ||
diff --git a/2024/22/day22a.cpp b/2024/22/day22a.cpp new file mode 100644 index 0000000..b2adfdc --- /dev/null +++ b/2024/22/day22a.cpp | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #include <algorithm> | ||
| 2 | #include <cstdint> | ||
| 3 | #include <iostream> | ||
| 4 | #include <map> | ||
| 5 | #include <queue> | ||
| 6 | #include <ranges> | ||
| 7 | #include <set> | ||
| 8 | #include <sstream> | ||
| 9 | #include <string> | ||
| 10 | #include <string_view> | ||
| 11 | #include <vector> | ||
| 12 | using namespace std; | ||
| 13 | |||
| 14 | int64_t next(int64_t n) { | ||
| 15 | constexpr int64_t M = 16777216; | ||
| 16 | n = ((n*64) ^ n) % M; | ||
| 17 | n = ((n/32) ^ n) % M; | ||
| 18 | n = ((n*2048) ^ n) % M; | ||
| 19 | return n; | ||
| 20 | } | ||
| 21 | |||
| 22 | int main() { | ||
| 23 | int64_t s; | ||
| 24 | int64_t tot = 0; | ||
| 25 | while (cin >> s) { | ||
| 26 | for (int i = 0; i < 2000; i++) | ||
| 27 | s = next(s); | ||
| 28 | tot += s; | ||
| 29 | } | ||
| 30 | cout << tot << endl; | ||
| 31 | return 0; | ||
| 32 | } | ||
diff --git a/2024/22/day22b.cpp b/2024/22/day22b.cpp new file mode 100644 index 0000000..abd9e6f --- /dev/null +++ b/2024/22/day22b.cpp | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | #include <algorithm> | ||
| 2 | #include <cstdint> | ||
| 3 | #include <iostream> | ||
| 4 | #include <map> | ||
| 5 | #include <queue> | ||
| 6 | #include <ranges> | ||
| 7 | #include <set> | ||
| 8 | #include <sstream> | ||
| 9 | #include <string> | ||
| 10 | #include <string_view> | ||
| 11 | #include <vector> | ||
| 12 | using namespace std; | ||
| 13 | |||
| 14 | class Seq { | ||
| 15 | public: | ||
| 16 | int64_t k; | ||
| 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 | |||
| 40 | int64_t next(int64_t n) { | ||
| 41 | constexpr int64_t M = 16777216; | ||
| 42 | n = ((n*64) ^ n) % M; | ||
| 43 | n = ((n/32) ^ n) % M; | ||
| 44 | n = ((n*2048) ^ n) % M; | ||
| 45 | return n; | ||
| 46 | } | ||
| 47 | |||
| 48 | int main() { | ||
| 49 | int64_t s; | ||
| 50 | vector<vector<pair<int, int>>> spc; | ||
| 51 | vector<map<int64_t, int64_t>> tt; | ||
| 52 | set<int64_t> seqs; | ||
| 53 | |||
| 54 | for (int i = 0; cin >> s; i++) { | ||
| 55 | spc.push_back(vector<pair<int, int>>()); | ||
| 56 | tt.push_back(map<int64_t, int64_t>()); | ||
| 57 | |||
| 58 | for (int j = 0; j < 2000; j++) { | ||
| 59 | int64_t t = next(s); | ||
| 60 | spc[i].push_back({t%10, t%10 - s%10}); | ||
| 61 | s = t; | ||
| 62 | if (j >= 3) { | ||
| 63 | auto k = Seq(spc[i], j).k; | ||
| 64 | seqs.insert(k); | ||
| 65 | if (tt[i].count(k) == 0) | ||
| 66 | tt[i][k] = spc[i][j].first; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | Seq seq; | ||
| 72 | int64_t best = 0; | ||
| 73 | for (auto k : seqs) { | ||
| 74 | Seq seq(k); | ||
| 75 | int64_t tot = 0; | ||
| 76 | for (unsigned i = 0; i < spc.size(); i++) | ||
| 77 | tot += tt[i][seq.k]; | ||
| 78 | best = max(best, tot); | ||
| 79 | }; | ||
| 80 | |||
| 81 | cout << best << endl; | ||
| 82 | |||
| 83 | return 0; | ||
| 84 | } | ||
