aboutsummaryrefslogtreecommitdiff
path: root/src/2016/day22/aoc.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/2016/day22/aoc.h')
-rw-r--r--src/2016/day22/aoc.h36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/2016/day22/aoc.h b/src/2016/day22/aoc.h
index b0ad2ba..d368f22 100644
--- a/src/2016/day22/aoc.h
+++ b/src/2016/day22/aoc.h
@@ -3,5 +3,39 @@
#include <vector>
namespace aoc2016 {
+
+struct grid_node {
+ int x = 0;
+ int y = 0;
+ int s[4] = {0}; // size, used, avail, use%
+
+ void get_number(const char** pp, int* d) {
+ const char* p = *pp;
+ while (*p >= '0' && *p <= '9') {
+ *d = *d * 10 + *p - '0';
+ p++;
+ }
+ *pp = p;
+ }
+
+ grid_node(line_view lv) {
+ int* ds[] = {&x, &y, s, s + 1, s + 2, s + 3};
+ const char* p = lv.line;
+ int i{0};
+ while (p < lv.line + lv.length) {
+ if (*p >= '0' && *p <= '9') {
+ get_number(&p, ds[i]);
+ i++;
+ }
+ p++;
+ }
+ }
+
+ void print() const noexcept { printf("(%d,%d) %d %d %d %d\n", x, y, s[0], s[1], s[2], s[3]); }
+ friend bool operator<(const grid_node& n1, const grid_node& n2) {
+ return n1.s[2] > n2.s[2] ? true : n1.s[2] < n2.s[2] ? false : n1.s[0] > n2.s[0];
+ }
+};
+
std::pair<int64_t, int64_t> day22(line_view);
-}
+} // namespace aoc2016