aboutsummaryrefslogtreecommitdiff
path: root/src/2016/day11/aoc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/2016/day11/aoc.cpp')
-rw-r--r--src/2016/day11/aoc.cpp111
1 files changed, 110 insertions, 1 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