aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2023-01-17 17:50:45 +0800
committerkaiwu <kaiwu2004@gmail.com>2023-01-17 17:50:45 +0800
commitaa6d09e27ea9bc898c7da4078a2b9e777c6253a8 (patch)
treef4f80504a66bf78c384f72923528d9d6bceccf19
parent2bfaa055be9983352bf11212169d31aa8fbb525e (diff)
downloadadvent-of-code-aa6d09e27ea9bc898c7da4078a2b9e777c6253a8.tar.gz
advent-of-code-aa6d09e27ea9bc898c7da4078a2b9e777c6253a8.zip
2022 day19 part2 branch trimming
-rw-r--r--src/2022/day19/aoc.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/2022/day19/aoc.cpp b/src/2022/day19/aoc.cpp
index 737c230..f368561 100644
--- a/src/2022/day19/aoc.cpp
+++ b/src/2022/day19/aoc.cpp
@@ -4,7 +4,7 @@
namespace aoc2022 {
-static const int total = 24;
+static const int total = 32;
struct build_result {
int products[4] = {0, 0, 0, 0}; // ore,clay,obsi,geod
@@ -99,17 +99,17 @@ bool can_build(const blueprint& b, const build_result& r, int i) {
// 29 24| ms: 1 21 8 9 | rs: 1 3 2 2
// 30 24| ms: 2 10 4 1 | rs: 2 6 3 1
void build_product(const blueprint& b, build_result r, std::vector<build_result>& rs) {
- bool done{false};
- for (int i = 3; i >= 0 && !done; i--) {
+ bool ds[4] = {false, false, false, false};
+ for (int i = 3; i >= 0; i--) {
auto r0 = r;
if (can_build(b, r0, i)) {
r0 = build_robot(i, r0, b);
build_product(r0, i);
rs.push_back(r0);
- done = i > 1; // best senario
+ ds[i] = true;
}
}
- if (!done) {
+ if (!ds[3] && !ds[2] && !(ds[1] && ds[0])) {
build_product(r, 4);
rs.push_back(r);
}