aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

commit 764828d4c41aa52709037cf46eb4f3a67e16cccc
parent b0f15d139c284d0140e56fb6acfa5e62e4fbde60
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun, 22 Dec 2024 10:12:09 +0100

Now day 22 part 2 is reasonably fast

Diffstat:
M2024/22/day22b.cpp | 13++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/2024/22/day22b.cpp b/2024/22/day22b.cpp @@ -28,6 +28,7 @@ int main() { int64_t s; vector<vector<pair<int, int>>> spc; vector<map<int64_t, int64_t>> tt; + map<int64_t, int64_t> sums; set<int64_t> seqs; for (int i = 0; cin >> s; i++) { @@ -47,14 +48,12 @@ int main() { } } - int64_t best = 0; - for (auto k : seqs) { - int64_t tot = 0; - for (unsigned i = 0; i < spc.size(); i++) - tot += tt[i][k]; - best = max(best, tot); - }; + for (unsigned i = 0; i < spc.size(); i++) + for (auto [k, v] : tt[i]) + sums[k] += v; + auto values = views::values(sums); + auto best = *max_element(values.begin(), values.end()); cout << best << endl; return 0;