2024 day 22

This commit is contained in:
eriedaberrie 2024-12-21 22:03:46 -08:00
parent aa6c678c77
commit c4e45dedab
2 changed files with 82 additions and 0 deletions

27
2024/22/main-1.cpp Normal file
View file

@ -0,0 +1,27 @@
#include "../../include/aoc.hpp"
#include <bits/stdc++.h>
using namespace std;
ll mp(ll n, ll o) { return (n ^ o) % 16777216; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
vector<int> 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';
}

55
2024/22/main-2.cpp Normal file
View file

@ -0,0 +1,55 @@
#include "../../include/aoc.hpp"
#include <bits/stdc++.h>
using namespace std;
size_t h(vector<char> &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<int> secrets;
ll n;
while (cin >> n) {
secrets.push_back(n);
}
unordered_map<size_t, int> m;
for (ll s : secrets) {
char sp = s % 10;
vector<char> ss;
unordered_set<size_t> done;
for (int i = 0; i < 2000; i++) {
char 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';
}