Work on an actual algorithm for day 17.

This commit is contained in:
2019-12-23 18:45:16 +01:00
parent 46b2ae6ef0
commit ebb85b2257

View File

@@ -8,11 +8,11 @@
namespace { namespace {
typedef aoc2019::Point<int, 2> point_t; typedef aoc2019::Point<int, 2> point_t;
const std::unordered_map<point_t, std::int64_t> DIRECTIONS{ const std::unordered_map<char, point_t> DIRECTIONS{
{{0, -1}, 1}, {'^', {0, -1}},
{{0, 1}, 2}, {'>', {0, 1}},
{{-1, 0}, 3}, {'v', {1, 0}},
{{1, 0}, 4}, {'<', {-1, 0}},
}; };
std::unordered_map<point_t, char> read_scaffold(const std::deque<std::int64_t> &data) { std::unordered_map<point_t, char> read_scaffold(const std::deque<std::int64_t> &data) {
@@ -21,6 +21,10 @@ namespace {
std::unordered_map<point_t, char> map; std::unordered_map<point_t, char> map;
for (auto n : data) { for (auto n : data) {
if (n == '\n') { if (n == '\n') {
if (x == 0) {
// Double newline, end of map
break;
}
++y; ++y;
x = 0; x = 0;
continue; continue;
@@ -49,7 +53,7 @@ void aoc2019::day17_part1(std::istream &input, std::ostream &output) {
if (entry.second == '.') continue; if (entry.second == '.') continue;
bool is_intersection = std::all_of(DIRECTIONS.begin(), DIRECTIONS.end(), [&map, &entry](auto &x) { bool is_intersection = std::all_of(DIRECTIONS.begin(), DIRECTIONS.end(), [&map, &entry](auto &x) {
auto it = map.find(x.first + entry.first); auto it = map.find(x.second + entry.first);
return it != map.end() && it->second != '.'; return it != map.end() && it->second != '.';
}); });