#include "aoc.h" #include #include namespace aoc2017 { hexagon route(hexagon h, const std::vector& 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 q; std::set 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 day11(line_view file) { std::vector ds; const char* p0 = file.line; const char* p1 = p0; line_view d6[] = {"n", "ne", "nw", "se", "sw", "s"}; while (p1 < file.line + file.length) { if (*p1 == ',' || *p1 == '\n') { line_view d{p0, p1}; for (int i = 0; i < 6; i++) { if (d6[i] == d) { ds.push_back(static_cast(i)); break; } } p0 = p1 + 1; } p1++; } int max{INT32_MIN}; auto d = route({0, 0, 0}, ds, &max); return {d.a + d.r + d.c, max}; } } // namespace aoc2017