From 119fc813547bcb9f551f0d449e2a43bf626cc850 Mon Sep 17 00:00:00 2001 From: eriedaberrie Date: Sat, 21 Dec 2024 22:03:46 -0800 Subject: [PATCH] 2024 day 22 --- 2024/22/main-1.cpp | 27 +++++++++++++++++++++++ 2024/22/main-2.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 2024/22/main-1.cpp create mode 100644 2024/22/main-2.cpp diff --git a/2024/22/main-1.cpp b/2024/22/main-1.cpp new file mode 100644 index 0000000..45d1823 --- /dev/null +++ b/2024/22/main-1.cpp @@ -0,0 +1,27 @@ +#include "../../include/aoc.hpp" +#include +using namespace std; + +ll mp(ll n, ll o) { return (n ^ o) % 16777216; } + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + vector secrets; + int n; + while (cin >> n) { + secrets.push_back(n); + } + + ll count = 0; + for (ll s : secrets) { + for (int i = 0; i < 2000; i++) { + s = mp(s * 64, s); + s = mp(s / 32, s); + s = mp(s * 2048, s); + } + count += s; + } + cout << count << '\n'; +} diff --git a/2024/22/main-2.cpp b/2024/22/main-2.cpp new file mode 100644 index 0000000..c9d06e3 --- /dev/null +++ b/2024/22/main-2.cpp @@ -0,0 +1,55 @@ +#include "../../include/aoc.hpp" +#include +using namespace std; + +size_t h(vector &v) { + size_t ret = 0; + for (int i = 0; i < 4; i++) { + ret += v[v.size() - 1 - i] << (i * 8); + } + return ret; +} + +ll mp(ll n, ll o) { return (n ^ o) % 16777216; } + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + vector secrets; + ll n; + while (cin >> n) { + secrets.push_back(n); + } + + unordered_map m; + for (ll s : secrets) { + int sp = s % 10; + vector ss; + unordered_set done; + for (int i = 0; i < 2000; i++) { + int oldsp = sp; + s = mp(s * 64, s); + s = mp(s / 32, s); + s = mp(s * 2048, s); + sp = s % 10; + ss.push_back(sp - oldsp); + if (ss.size() >= 4) { + auto hss = h(ss); + if (done.contains(hss)) { + continue; + } + done.insert(hss); + m[hss] += sp; + } + } + } + + int mx = 0; + for (auto n : m) { + if (n.second > mx) { + mx = n.second; + } + } + cout << mx << '\n'; +}