#pragma once #include "common.h" #include 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() {} 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]; } }; struct storage_grid { std::vector 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& vs) { for (auto& n : vs) { auto& node = get(n.x, n.y); memcpy(node.s, n.s, sizeof(int) * 4); } } void print(int m) { 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("(%02d)\t", n.s[2]); } printf("\n"); } } }; std::pair day22(line_view); } // namespace aoc2016