diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-12-19 21:03:24 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-12-19 21:03:24 +0800 |
commit | 46a32e79d1d247d15e6e683e94e197f78aa09ea8 (patch) | |
tree | e288857ea5d1f80cd06241cc2f03ce805473617b /src/2022/day15/aoc.h | |
parent | b29b67b0d72f29dcaa46a06d6e72e46f62a748fe (diff) | |
download | advent-of-code-46a32e79d1d247d15e6e683e94e197f78aa09ea8.tar.gz advent-of-code-46a32e79d1d247d15e6e683e94e197f78aa09ea8.zip |
2022 day15 stay calm no panic
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); } |