simplify
This commit is contained in:
parent
ebdab4a2e0
commit
fb82f11b39
17
src/day2.cpp
17
src/day2.cpp
@ -24,6 +24,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
std::cout << "Part 1: " << part_1(v) << std::endl;
|
std::cout << "Part 1: " << part_1(v) << std::endl;
|
||||||
std::cout << "Part 2: " << part_2(v) << std::endl;
|
std::cout << "Part 2: " << part_2(v) << std::endl;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t part_1(const std::vector<Data> &v) {
|
int64_t part_1(const std::vector<Data> &v) {
|
||||||
@ -60,24 +61,10 @@ int64_t solve_n(int64_t n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int64_t part_2(const std::vector<Data> &v) {
|
int64_t part_2(const std::vector<Data> &v) {
|
||||||
int64_t ans{0};
|
return std::accumulate(v.begin(), v.end(), 0ll, [](int64_t acc, Data d) {
|
||||||
for (auto d : v) {
|
|
||||||
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) {
|
for (auto n{d.min}; n <= d.max; ++n) {
|
||||||
acc += solve_n(n);
|
acc += solve_n(n);
|
||||||
}
|
}
|
||||||
return acc;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user