diff options
Diffstat (limited to 'src/2022/day15/aoc.h')
-rw-r--r-- | src/2022/day15/aoc.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/2022/day15/aoc.h b/src/2022/day15/aoc.h index 87c3208..7540490 100644 --- a/src/2022/day15/aoc.h +++ b/src/2022/day15/aoc.h @@ -24,6 +24,8 @@ struct sensor { pos p0; pos p1; + line() {} + line(pos x, pos y): p0(x), p1(y) {} friend bool operator<(const line& l1, const line& l2) { return l1.p0.x < l2.p0.x; } @@ -39,6 +41,18 @@ struct sensor { return std::abs(p1.x - p2.x) + std::abs(p1.y - p2.y); } + std::pair<int, std::vector<line>> lines() const noexcept { + auto d = mdistance(ps[0], ps[1]); + std::vector<line> ls; + for(int y = ps[0].y - d; y <= ps[0].y + d; y++) { + auto dx = d - std::abs(ps[0].y - y); + pos p0 = {ps[0].x - dx, y}; + pos p1 = {ps[0].x + dx, y}; + ls.emplace_back(p0, p1); + } + return {ps[0].y - d,ls}; + } + void get_number(const char** pp, int* d) { const char *p = *pp; int sign = 1; @@ -83,6 +97,6 @@ struct sensor { } }; -std::pair<int, int> day15(line_view); +std::pair<int, size_t> day15(line_view); } |