aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2023-01-26 22:27:02 +0800
committerkaiwu <kaiwu2004@gmail.com>2023-01-26 22:27:02 +0800
commitff62813afc449383b93e80dece1075c9315dbb21 (patch)
tree0b1b00415f0de70879b9143b087f0fe26117b757
parent936a3bbbb950f35ec37ab2db2964c41883cba254 (diff)
downloadadvent-of-code-ff62813afc449383b93e80dece1075c9315dbb21.tar.gz
advent-of-code-ff62813afc449383b93e80dece1075c9315dbb21.zip
2016 day22 part2
-rw-r--r--src/2016/day22/aoc.cpp13
-rw-r--r--src/2016/day22/aoc.h27
-rw-r--r--src/2016/day22/input010
-rw-r--r--test/test_2016.cpp4
4 files changed, 50 insertions, 4 deletions
diff --git a/src/2016/day22/aoc.cpp b/src/2016/day22/aoc.cpp
index b4201e3..0a48c4e 100644
--- a/src/2016/day22/aoc.cpp
+++ b/src/2016/day22/aoc.cpp
@@ -24,14 +24,23 @@ void find_pairs(size_t x, const std::vector<grid_node>& ns, int* count) {
std::pair<int64_t, int64_t> day22(line_view file) {
std::vector<grid_node> ns;
+ int maxx{INT32_MIN};
+ int maxy{INT32_MIN};
- per_line(file, [&ns](line_view lv) {
+ per_line(file, [&ns, &maxx, &maxy](line_view lv) {
if (*lv.line == '/') {
- ns.emplace_back(lv);
+ grid_node n{lv};
+ maxx = std::max(maxx, n.x);
+ maxy = std::max(maxy, n.y);
+ ns.emplace_back(n);
}
return true;
});
+ storage_grid grid(maxx + 1, maxy + 1);
+ grid.load(ns);
+ grid.print();
+
// std::sort(ns.begin(), ns.end());
// for (auto& n : ns) {
// n.print();
diff --git a/src/2016/day22/aoc.h b/src/2016/day22/aoc.h
index d368f22..ac5d83f 100644
--- a/src/2016/day22/aoc.h
+++ b/src/2016/day22/aoc.h
@@ -18,6 +18,7 @@ struct grid_node {
*pp = p;
}
+ grid_node() {}
grid_node(line_view lv) {
int* ds[] = {&x, &y, s, s + 1, s + 2, s + 3};
const char* p = lv.line;
@@ -37,5 +38,31 @@ struct grid_node {
}
};
+struct storage_grid {
+ std::vector<grid_node> ns;
+ int width;
+ int height;
+
+ storage_grid(int w, int h) : width(w), height(h) { ns.resize(width * height); }
+ grid_node& get(int x, int y) { return ns[y * width + x]; }
+
+ void load(const std::vector<grid_node>& vs) {
+ for (auto& n : vs) {
+ auto& node = get(n.x, n.y);
+ memcpy(node.s, n.s, sizeof(int) * 4);
+ }
+ }
+
+ void print() {
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ auto& n = get(x, y);
+ printf("(%02d/%02d)\t", n.s[1], n.s[0]);
+ }
+ printf("\n");
+ }
+ }
+};
+
std::pair<int64_t, int64_t> day22(line_view);
} // namespace aoc2016
diff --git a/src/2016/day22/input0 b/src/2016/day22/input0
index e69de29..5cdf80f 100644
--- a/src/2016/day22/input0
+++ b/src/2016/day22/input0
@@ -0,0 +1,10 @@
+Filesystem Size Used Avail Use%
+/dev/grid/node-x0-y0 10T 8T 2T 80%
+/dev/grid/node-x0-y1 11T 6T 5T 54%
+/dev/grid/node-x0-y2 32T 28T 4T 87%
+/dev/grid/node-x1-y0 9T 7T 2T 77%
+/dev/grid/node-x1-y1 8T 0T 8T 0%
+/dev/grid/node-x1-y2 11T 7T 4T 63%
+/dev/grid/node-x2-y0 10T 6T 4T 60%
+/dev/grid/node-x2-y1 9T 8T 1T 88%
+/dev/grid/node-x2-y2 9T 6T 3T 66%
diff --git a/test/test_2016.cpp b/test/test_2016.cpp
index 092ad7a..2e62ccb 100644
--- a/test/test_2016.cpp
+++ b/test/test_2016.cpp
@@ -197,9 +197,9 @@ TEST_CASE("Scrambled Letters and Hash", "[2016]") {
TEST_CASE("Grid Computing", "[2016]") {
- line_view lv = load_file("../src/2016/day22/input");
+ line_view lv = load_file("../src/2016/day22/input0");
auto p = aoc2016::day22(lv);
- REQUIRE(990 == p.first);
+ // REQUIRE(990 == p.first);
REQUIRE(0 == p.second);
}