diff options
author | kaiwu <kaiwu2004@gmail.com> | 2023-01-06 14:53:31 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2023-01-06 14:53:31 +0800 |
commit | cada26566ccd0fd439f4490c4cee029148bf189b (patch) | |
tree | c9509b10e83418f45b885781f4010a2544ed180e /src/2022/day24/aoc.cpp | |
parent | c425d2235cb1bb812472de9da9777da07392ba49 (diff) | |
download | advent-of-code-cada26566ccd0fd439f4490c4cee029148bf189b.tar.gz advent-of-code-cada26566ccd0fd439f4490c4cee029148bf189b.zip |
2022 day24 formatting
Diffstat (limited to 'src/2022/day24/aoc.cpp')
-rw-r--r-- | src/2022/day24/aoc.cpp | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/src/2022/day24/aoc.cpp b/src/2022/day24/aoc.cpp index 1e55468..825da1e 100644 --- a/src/2022/day24/aoc.cpp +++ b/src/2022/day24/aoc.cpp @@ -1,6 +1,6 @@ #include "aoc.h" -#include <set> #include <deque> +#include <set> namespace aoc2022 { @@ -12,9 +12,7 @@ struct pos { friend bool operator<(pos p1, pos p2) { return p1.x < p2.x ? true : p1.x > p2.x ? false : p1.y < p2.y ? true : p1.y > p2.y ? false : p1.t < p2.t; } - bool operator==(pos p) const noexcept { - return x == p.x && y == p.y; - } + bool operator==(pos p) const noexcept { return x == p.x && y == p.y; } }; bool is_valid(pos p, valley& v, std::set<pos>& visited) { @@ -27,8 +25,9 @@ bool is_valid(pos p, valley& v, std::set<pos>& visited) { auto blz = v.at(px.t); auto find = [&blz](blizzard b) -> bool { - for(auto& bx : blz) { - if (bx == b) return true; + for (auto& bx : blz) { + if (bx == b) + return true; } return false; }; @@ -42,7 +41,7 @@ int expedition(pos p, pos target, valley& v, std::set<pos>& visited) { std::deque<pos> q; q.push_back(p); - while(!q.empty()) { + while (!q.empty()) { auto size = q.size(); while (size-- > 0) { pos px = q.front(); @@ -52,11 +51,8 @@ int expedition(pos p, pos target, valley& v, std::set<pos>& visited) { return px.t; } pos ps[5] = { - {px.x, px.y+1, px.t + 1}, - {px.x+1, px.y, px.t + 1}, - {px.x, px.y-1, px.t + 1}, - {px.x-1, px.y, px.t + 1}, - {px.x, px.y, px.t + 1}, + {px.x, px.y + 1, px.t + 1}, {px.x + 1, px.y, px.t + 1}, {px.x, px.y - 1, px.t + 1}, + {px.x - 1, px.y, px.t + 1}, {px.x, px.y, px.t + 1}, }; for (int i = 0; i < 5; i++) { if (is_valid(ps[i], v, visited)) { @@ -70,7 +66,7 @@ int expedition(pos p, pos target, valley& v, std::set<pos>& visited) { std::pair<int, int> day24(line_view file) { // valley v{8,6}; //sample - valley v{152,22}; + valley v{152, 22}; int height{0}; per_line(file, [&v, &height](line_view lv) { @@ -88,5 +84,4 @@ std::pair<int, int> day24(line_view file) { // printf("%d %d %d\n", m1, m2, m3); return {m1, m3}; } -} - +} // namespace aoc2022 |