diff options
Diffstat (limited to 'src/2017/day11/aoc.cpp')
-rw-r--r-- | src/2017/day11/aoc.cpp | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/2017/day11/aoc.cpp b/src/2017/day11/aoc.cpp index b9b599a..c7e5ffd 100644 --- a/src/2017/day11/aoc.cpp +++ b/src/2017/day11/aoc.cpp @@ -1,7 +1,52 @@ #include "aoc.h" +#include <deque> +#include <set> namespace aoc2017 { +hexagon route(hexagon h, const std::vector<hd>& hds, int* max) { + for (auto& hd : hds) { + h = h.neighbour(hd); + int d = h.a + h.r + h.c; + if (d > *max) { + *max = d; + } + } + return h; +} + +int bfs(hexagon start, hexagon target) { + int step{0}; + std::deque<hexagon> q; + std::set<hexagon> visited; + q.push_back(start); + + while (!q.empty()) { + auto s = q.size(); + while (s-- > 0) { + auto h = q.front(); + q.pop_front(); + if (h == target) { + return step; + } + + hexagon ns[6] = { + h.neighbour(hd::n), h.neighbour(hd::nw), h.neighbour(hd::ne), + h.neighbour(hd::sw), h.neighbour(hd::se), h.neighbour(hd::s), + }; + for (auto& n : ns) { + if (visited.find(n) == visited.end()) { + visited.insert(n); + q.push_back(n); + } + } + } + step++; + } + + return INT32_MAX; +} + std::pair<int64_t, int64_t> day11(line_view file) { std::vector<hd> ds; const char* p0 = file.line; @@ -21,7 +66,9 @@ std::pair<int64_t, int64_t> day11(line_view file) { p1++; } - return {0, 0}; + int max{INT32_MIN}; + auto d = route({0, 0, 0}, ds, &max); + return {d.a + d.r + d.c, max}; } } // namespace aoc2017 |