From 9e9321541a00be5f1d73eb25ccc100c1afd22cfc Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Sun, 12 Dec 2021 08:05:13 +0000 Subject: [PATCH] Tidyup 2021 day 12 puzzles --- 2021/puzzle-12-02.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/2021/puzzle-12-02.cc b/2021/puzzle-12-02.cc index 44d1417..61cf89e 100644 --- a/2021/puzzle-12-02.cc +++ b/2021/puzzle-12-02.cc @@ -12,9 +12,9 @@ using Paths = std::multimap; using Route = std::vector; -auto is_upper_case(std::string const& s) -> bool { return std::isupper(s[0]) ? true : false; } +auto is_upper_case(std::string const& s) -> bool { return std::isupper(s[0]) == 1; } -auto is_visitable(Route const& route, Paths const& paths, std::string const& proposed) -> bool +auto is_visitable(Route const& route, std::string const& proposed) -> bool { if (is_upper_case(proposed)) { return true; @@ -22,7 +22,7 @@ auto is_visitable(Route const& route, Paths const& paths, std::string const& pro std::set visited; bool little_visited_twice{false}; - for (auto r : route) { + for (const auto& r : route) { if (!is_upper_case(r)) { if (visited.contains(r)) { little_visited_twice = true; @@ -50,7 +50,7 @@ void visit(Route& route, Paths const& paths, Fn visitor) } for (auto it{path_begin}; it != path_end; ++it) { - if (is_visitable(route, paths, it->second)) { + if (is_visitable(route, it->second)) { route.push_back(it->second); visit(route, paths, visitor); route.pop_back(); @@ -82,10 +82,7 @@ auto main() -> int unsigned route_count{0}; Route route{"start"}; - visit(route, paths, [&route_count](auto const& route, auto const&) { - for (auto r : route) { - std::cout << " " << r; - } + visit(route, paths, [&route_count](auto const&, auto const&) { std::cout << "\n"; ++route_count; });