From ebb85b2257bbd62b951aad6ad52a74bd0e538d51 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Mon, 23 Dec 2019 18:45:16 +0100 Subject: [PATCH] Work on an actual algorithm for day 17. --- 2019/src/day17.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 != '.'; });