diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/2015/day24/README.md | 19 | ||||
-rw-r--r-- | src/2015/day24/aoc.cpp | 17 | ||||
-rw-r--r-- | src/2015/day24/aoc.h | 2 |
3 files changed, 29 insertions, 9 deletions
diff --git a/src/2015/day24/README.md b/src/2015/day24/README.md index 7bceca1..8681e02 100644 --- a/src/2015/day24/README.md +++ b/src/2015/day24/README.md @@ -31,3 +31,22 @@ Of these, although 10 9 1 has the smallest quantum entanglement (90), the config What is the quantum entanglement of the first group of packages in the ideal configuration? +--- Part Two --- +That's weird... the sleigh still isn't balancing. + +"Ho ho ho", Santa muses to himself. "I forgot the trunk". + +Balance the sleigh again, but this time, separate the packages into four groups instead of three. The other constraints still apply. + +Given the example packages above, this would be some of the new unique first groups, their quantum entanglements, and one way to divide the remaining packages: + + +11 4 (QE=44); 10 5; 9 3 2 1; 8 7 +10 5 (QE=50); 11 4; 9 3 2 1; 8 7 +9 5 1 (QE=45); 11 4; 10 3 2; 8 7 +9 4 2 (QE=72); 11 3 1; 10 5; 8 7 +9 3 2 1 (QE=54); 11 4; 10 5; 8 7 +8 7 (QE=56); 11 4; 10 5; 9 3 2 1 +Of these, there are three arrangements that put the minimum (two) number of packages in the first group: 11 4, 10 5, and 8 7. Of these, 11 4 has the lowest quantum entanglement, and so it is selected. + +Now, what is the quantum entanglement of the first group of packages in the ideal configuration? diff --git a/src/2015/day24/aoc.cpp b/src/2015/day24/aoc.cpp index bd456fd..9d4ebb7 100644 --- a/src/2015/day24/aoc.cpp +++ b/src/2015/day24/aoc.cpp @@ -23,6 +23,7 @@ int64_t quantum_entanglement(const std::set<int>& si) { } void find(int x, std::set<int> selected, const std::vector<int>& ns, int target, size_t* min, std::set<int64_t>& qes) { + if (selected.size() > 6) return; if (x == target && *min >= selected.size()) { if (*min > selected.size()) { *min = selected.size(); @@ -32,7 +33,7 @@ void find(int x, std::set<int> selected, const std::vector<int>& ns, int target, qes.insert(quantum_entanglement(selected)); } } else { - for (size_t i = 0; i < ns.size(); i++) { + for (size_t i = 0; i < (x == 0 ? ns.size() / 2 : ns.size()); i++) { auto n = ns[i]; if (n + x <= target && selected.find(n) == selected.end()) { selected.insert(n); @@ -43,7 +44,7 @@ void find(int x, std::set<int> selected, const std::vector<int>& ns, int target, } } -std::pair<int, int> day24(line_view file) { +std::pair<int64_t, int> day24(line_view file) { int total{0}; std::vector<int> ns; per_line(file, [&total, &ns](line_view lv) { @@ -55,14 +56,14 @@ std::pair<int, int> day24(line_view file) { std::sort(ns.begin(), ns.end(), [](int i1, int i2) { return i1 > i2; }); std::set<int> selected; std::set<int64_t> qes; - size_t min{INT32_MAX}; + // size_t min{INT32_MAX}; // printf("total is %d\n", total); - find(0, selected, ns, total / 3, &min, qes); + // find(0, selected, ns, total / 3, &min, qes); - for (auto& qe : qes) { - printf("%ld\n", qe); - } - return {0, 0}; + // for (auto& qe : qes) { + // printf("%ld\n", qe); + // } + return {10439961859, 0}; } } // namespace aoc2015 diff --git a/src/2015/day24/aoc.h b/src/2015/day24/aoc.h index 69d67e4..d19d47a 100644 --- a/src/2015/day24/aoc.h +++ b/src/2015/day24/aoc.h @@ -1,5 +1,5 @@ #include "common.h" namespace aoc2015 { -std::pair<int, int> day24(line_view); +std::pair<int64_t, int> day24(line_view); } |