From 8ce87461c0374abe992c0a6efcc7dc1b86a61205 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Mon, 7 Dec 2020 02:41:12 -0500 Subject: [PATCH] Lessen capture in recursive solution --- day7/day7.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/day7/day7.cpp b/day7/day7.cpp index 4cb183a..1df60e2 100644 --- a/day7/day7.cpp +++ b/day7/day7.cpp @@ -175,7 +175,7 @@ int part2(const std::vector &input) { int recursivePart2(const BagMap &bagMap, const std::string &toVisit = DESIRED_BAG) { std::vector childBags = bagMap.at(toVisit); - return std::accumulate(childBags.cbegin(), childBags.cend(), 0, [&](int total, const ContainedBag &bag) { + return std::accumulate(childBags.cbegin(), childBags.cend(), 0, [&bagMap](int total, const ContainedBag &bag) { return total + bag.getQuantity() + bag.getQuantity() * recursivePart2(bagMap, bag.getColor()); }); }