aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2023-01-20 15:16:36 +0800
committerkaiwu <kaiwu2004@gmail.com>2023-01-20 15:16:36 +0800
commitef26852c7af30a86688081bbc9e4418fe6382d0d (patch)
treea18087d9763ca38bb19f4d1149e4a16a8f192c25
parent52464b084b647fcf18a5110dade2580cb8903aab (diff)
downloadadvent-of-code-ef26852c7af30a86688081bbc9e4418fe6382d0d.tar.gz
advent-of-code-ef26852c7af30a86688081bbc9e4418fe6382d0d.zip
2016 day11 bfs
-rw-r--r--src/2016/day11/aoc.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/2016/day11/aoc.cpp b/src/2016/day11/aoc.cpp
index ffd2fbe..32b969a 100644
--- a/src/2016/day11/aoc.cpp
+++ b/src/2016/day11/aoc.cpp
@@ -77,8 +77,6 @@ bool any_at(const std::vector<ritem>& rs, int f) {
bool empty(const std::vector<ritem>& rs, int f) { return !any_at(rs, f); }
-// bfs ???
-// goal is to get every ritem in rs with value (4,4)
// 1. in every step, modify fs[0] or fs[1] in each ritem
// 2. at minimal 1 must be modified, at most, 2 can be modified
// 3. chip fs[1] can only be modified if
@@ -91,10 +89,22 @@ bool empty(const std::vector<ritem>& rs, int f) { return !any_at(rs, f); }
// 6. either modify fs[0] and fs[1] of the same ritem
// or modify two fs[0] or two fs[1]
// 7. GGM is ok, GMM is not
-int move_ritem(int floor, const std::vector<ritem>& r) {
+struct ritem_f {
+ std::vector<ritem> rs;
+ int f;
+};
+
+std::vector<ritem_f> choices(const ritem_f& r) {
+ // int nf = next_floor(r.f);
+ return {};
+}
+
+// bfs
+// goal is to get every ritem in rs with value (4,4)
+int move_ritem(int f, const std::vector<ritem>& r) {
int step = 0;
- std::deque<std::vector<ritem>> q;
- q.push_back(r);
+ std::deque<ritem_f> q;
+ q.push_back({r, f});
while (!q.empty()) {
auto s = q.size();
@@ -102,10 +112,14 @@ int move_ritem(int floor, const std::vector<ritem>& r) {
auto r0 = q.front();
q.pop_front();
- if (all_at(r0, 4)) {
+ if (all_at(r0.rs, 4)) {
return step;
} else {
// push to q every other next possible state of r0
+ auto nexts = choices(r0);
+ for (auto& n : nexts) {
+ q.push_back(n);
+ }
}
}
step++;
@@ -118,6 +132,7 @@ std::pair<int64_t, int64_t> day11(line_view) {
setup_demo(rs);
int min = move_ritem(1, rs);
- return {min, 0};
+ printf("%d\n", min);
+ return {0, 0};
}
} // namespace aoc2016