diff --git a/2019/src/day17.cpp b/2019/src/day17.cpp index ebce718..3252eb1 100644 --- a/2019/src/day17.cpp +++ b/2019/src/day17.cpp @@ -8,11 +8,11 @@ namespace { typedef aoc2019::Point point_t; - const std::unordered_map DIRECTIONS{ - {{0, -1}, 1}, - {{0, 1}, 2}, - {{-1, 0}, 3}, - {{1, 0}, 4}, + const std::unordered_map DIRECTIONS{ + {'^', {0, -1}}, + {'>', {0, 1}}, + {'v', {1, 0}}, + {'<', {-1, 0}}, }; std::unordered_map read_scaffold(const std::deque &data) { @@ -21,6 +21,10 @@ namespace { std::unordered_map map; for (auto n : data) { if (n == '\n') { + if (x == 0) { + // Double newline, end of map + break; + } ++y; x = 0; continue; @@ -49,7 +53,7 @@ void aoc2019::day17_part1(std::istream &input, std::ostream &output) { if (entry.second == '.') continue; 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 != '.'; });