aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2023-01-20 11:38:52 +0800
committerkaiwu <kaiwu2004@gmail.com>2023-01-20 11:38:52 +0800
commit957d0f9f9b0c8c8c6889e496e807e178ae1a10da (patch)
treed30d3f7545604e48b9356a3b91fbfc3a3255c7c5
parent6596c0c0ecdc79a13a29a89d1c5528c52c0b52a2 (diff)
downloadadvent-of-code-957d0f9f9b0c8c8c6889e496e807e178ae1a10da.tar.gz
advent-of-code-957d0f9f9b0c8c8c6889e496e807e178ae1a10da.zip
2016 day11 model
-rw-r--r--src/2016/day11/aoc.cpp111
-rw-r--r--src/2016/day11/aoc.h49
2 files changed, 158 insertions, 2 deletions
diff --git a/src/2016/day11/aoc.cpp b/src/2016/day11/aoc.cpp
index 2381969..a3b0d63 100644
--- a/src/2016/day11/aoc.cpp
+++ b/src/2016/day11/aoc.cpp
@@ -1,6 +1,115 @@
#include "aoc.h"
+#include <set>
+
+// F4 . . . . . . . . . . .
+// F3 . . . . . . . HG HM RG RM
+// F2 . . . . PM . SM . . . .
+// F1 E TG TM PG . SG . . . . .
+//
+// F4 . . . . .
+// F3 . . . LG .
+// F2 . HG . . .
+// F1 E . HM . LM
+//
+// 0.
+// take everythong to the forth floor
+//
+// 1.
+// there is an elevator that can move between the four floors.
+// When you enter the containment area, you and the elevator will start on the first floor.
+//
+// 2.
+// Its capacity rating means it can carry at most yourself and two RTGs or microchips in any combination.
+//
+// 3.
+// As a security measure, the elevator will only function if it contains at least one RTG or microchip.
+//
+// 4.
+// The elevator always stops on each floor to recharge,
+// Each elevator stop counts as one step, even if nothing is added to or removed from it
+//
+// 5.
+// if a chip is ever left in the same area as another RTG,
+// and it's not connected to its own RTG, the chip will be fried.
+//
namespace aoc2016 {
-std::pair<int64_t, int64_t> day11(line_view) { return {0, 0}; }
+int next_floor(int f) {
+ static int df = 1;
+ if (f == 0)
+ df = 1;
+ if (f == 3)
+ df = -1;
+ return f + df;
+}
+
+struct rstatus {
+ ritem item;
+ bool matched = false;
+ bool fried = false;
+};
+
+static void check(size_t i, std::vector<rstatus>& rs) {
+ if (i < rs.size()) {
+ auto& r = rs[i];
+ if (!r.matched) {
+ for (size_t x = i + 1; x < rs.size(); x++) {
+ auto& r0 = rs[x];
+ if (r0.matched)
+ continue;
+ if (r.item.match(r0.item)) {
+ r.matched = true;
+ r0.matched = true;
+ break;
+ }
+ if (r.item.fried_with(r0.item)) {
+ r.fried = true;
+ r0.fried = true;
+ }
+ }
+ }
+ check(i + 1, rs);
+ }
+}
+
+bool isfine(const std::set<ritem>& rs) {
+ std::vector<rstatus> vs;
+ for (auto& r : rs) {
+ vs.emplace_back(r, false, false);
+ }
+ check(0, vs);
+ for (auto& s : vs) {
+ if (s.fried && !s.matched) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool isgood(const std::set<ritem>& rs) { // elevator
+ return rs.size() > 0 && rs.size() <= 2 && isfine(rs);
+}
+
+void setup_demo(std::vector<std::set<ritem>>& floors) {
+ std::set<ritem> f0 = {{chip, 0}, {chip, 1}};
+ std::set<ritem> f1 = {{gen, 0}};
+ std::set<ritem> f2 = {{gen, 1}};
+ std::set<ritem> f3 = {};
+ floors = {f0, f1, f2, f3};
+}
+
+void setup_input(std::vector<std::set<ritem>>& floors) {
+ std::set<ritem> f0 = {{chip, 0}, {gen, 0}, {gen, 1}, {gen, 2}};
+ std::set<ritem> f1 = {{chip, 1}, {chip, 2}};
+ std::set<ritem> f2 = {{chip, 3}, {gen, 3}, {chip, 4}, {gen, 4}};
+ std::set<ritem> f3 = {};
+ floors = {f0, f1, f2, f3};
+}
+
+std::pair<int64_t, int64_t> day11(line_view) {
+ std::vector<std::set<ritem>> floors;
+ setup_demo(floors);
+ return {0, 0};
+}
} // namespace aoc2016
diff --git a/src/2016/day11/aoc.h b/src/2016/day11/aoc.h
index 67f350c..5c89c3e 100644
--- a/src/2016/day11/aoc.h
+++ b/src/2016/day11/aoc.h
@@ -2,6 +2,53 @@
#include "common.h"
#include <vector>
+// F4 . . . . . . . . . . .
+// F3 . . . . . . . HG HM RG RM
+// F2 . . . . PM . SM . . . .
+// F1 E TG TM PG . SG . . . . .
+//
+// F4 . . . . .
+// F3 . . . LG .
+// F2 . HG . . .
+// F1 E . HM . LM
+//
+// 0.
+// take everythong to the forth floor
+//
+// 1.
+// there is an elevator that can move between the four floors.
+// When you enter the containment area, you and the elevator will start on the first floor.
+//
+// 2.
+// Its capacity rating means it can carry at most yourself and two RTGs or microchips in any combination.
+//
+// 3.
+// As a security measure, the elevator will only function if it contains at least one RTG or microchip.
+//
+// 4.
+// The elevator always stops on each floor to recharge,
+// Each elevator stop counts as one step, even if nothing is added to or removed from it
+//
+// 5.
+// if a chip is ever left in the same area as another RTG,
+// and it's not connected to its own RTG, the chip will be fried.
+//
+
namespace aoc2016 {
+
+enum rtype {
+ gen,
+ chip,
+};
+
+struct ritem {
+ rtype t;
+ int id;
+
+ friend bool operator<(ritem r1, ritem r2) { return r1.id < r2.id ? true : r1.id > r2.id ? false : r1.t < r2.t; }
+ bool match(ritem r) const noexcept { return id == r.id && t != r.t; }
+ bool fried_with(ritem r) const noexcept { return id != r.id && t != r.t; }
+};
+
std::pair<int64_t, int64_t> day11(line_view);
-}
+} // namespace aoc2016