From fb82f11b39d97ddd1825a49d4288fa5865aadc34 Mon Sep 17 00:00:00 2001 From: ajet Date: Mon, 15 Dec 2025 10:14:26 -1000 Subject: [PATCH] simplify --- src/day2.cpp | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/day2.cpp b/src/day2.cpp index 9f7be27..907f49d 100644 --- a/src/day2.cpp +++ b/src/day2.cpp @@ -24,6 +24,7 @@ int main() { } std::cout << "Part 1: " << part_1(v) << std::endl; std::cout << "Part 2: " << part_2(v) << std::endl; + return 0; } int64_t part_1(const std::vector &v) { @@ -60,24 +61,10 @@ int64_t solve_n(int64_t n) { } int64_t part_2(const std::vector &v) { - int64_t ans{0}; - for (auto d : v) { + return std::accumulate(v.begin(), v.end(), 0ll, [](int64_t acc, Data d) { for (auto n{d.min}; n <= d.max; ++n) { - ans += solve_n(n); - } - } - - // todo: dead code, delete me, then inline solve_n - int64_t foobar = std::accumulate(v.begin(), v.end(), 0, [&ans](int64_t acc, Data d) { - for (auto n{d.min}; n <= d.max; ++n) { - acc += solve_n(n); + acc += solve_n(n); } return acc; }); - - // help please :) - // why ans != foobar? looks like same but not same - // stepping through with debugger, it even seems the same on last iteration of accumulate - - return ans; }