From 346283bc8a2925b66255e55109354832dab7aacb Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Fri, 11 Nov 2022 08:27:18 -0800 Subject: [PATCH] warnings --- 2019/08.cpp | 2 +- 2019/12.cpp | 4 ++-- 2019/18.cpp | 16 +++++++--------- 2019/20.cpp | 7 +++---- 2019/23.cpp | 2 +- 2019/24.cpp | 18 ++++++++---------- intcode/src/Parser.cpp | 1 - 7 files changed, 22 insertions(+), 28 deletions(-) diff --git a/2019/08.cpp b/2019/08.cpp index 471dbb7..a76f710 100644 --- a/2019/08.cpp +++ b/2019/08.cpp @@ -17,7 +17,7 @@ auto Part1(std::string const& line) { std::distance(it, line.end()) >= 150; std::advance(it, 150)) { - auto zeros = std::count(it, it + 150, '0'); + auto zeros = std::size_t(std::count(it, it + 150, '0')); if (zeros < seen) { seen = zeros; part1 diff --git a/2019/12.cpp b/2019/12.cpp index 0ed5cc8..fc092eb 100644 --- a/2019/12.cpp +++ b/2019/12.cpp @@ -21,8 +21,8 @@ struct Particle { auto Step(std::vector & ps) { // apply gravity to update velocities auto n = ps.size(); - for (int i = 0; i+1 < n; i++) { - for (int j = i+1; j < n; j++) { + for (std::size_t i = 0; i+1 < n; i++) { + for (std::size_t j = i+1; j < n; j++) { auto v = (ps[i].pos < ps[j].pos) - (ps[i].pos > ps[j].pos); ps[i].vel += v; ps[j].vel -= v; diff --git a/2019/18.cpp b/2019/18.cpp index beb9bed..3df8e82 100644 --- a/2019/18.cpp +++ b/2019/18.cpp @@ -56,11 +56,11 @@ struct Map { auto FindFeatures(Map const& map) -> Features { Features features; - for (std::int64_t y = 0; y < map.rows.size(); y++) { - for (std::int64_t x = 0; x < map.rows[y].size(); x++) { - auto const c = map[{x,y}]; + for (std::size_t y = 0; y < map.rows.size(); y++) { + for (std::size_t x = 0; x < map.rows[y].size(); x++) { + auto const c = map[{std::int64_t(x),std::int64_t(y)}]; if ('#' != c && '.' != c) { - features[c] = {x,y}; + features[c] = {std::int64_t(x),std::int64_t(y)}; } } } @@ -69,8 +69,6 @@ auto FindFeatures(Map const& map) -> Features { auto FindDistancesFrom( Map const& map, - Features const& features, - Distances & distances, char const start_letter, Coord const start ) { @@ -91,7 +89,7 @@ auto FindDistancesFrom( // success, we've found a key, record the path if (c != start_letter && std::islower(c)) { - distances[start_letter][c] = {steps, doors}; + result[c] = {steps, doors}; continue; // don't walk beyond the key } @@ -113,7 +111,7 @@ auto FindDistances(Map const& map, Features const& features) { Distances distances; for (auto const [start_letter, start_coord] : features) { if (!std::isupper(start_letter)) { - FindDistancesFrom(map, features, distances, start_letter, start_coord); + distances[start_letter] = FindDistancesFrom(map, start_letter, start_coord); } } return distances; @@ -148,7 +146,7 @@ auto SolveMaze( for (auto& location : locations) { auto const save = location; - for (auto const [next, costneed] : distances.at(location)) { + for (auto const& [next, costneed] : distances.at(location)) { auto const [cost, need] = costneed; if ((need & ~keys).none()) { // no missing keys location = next; diff --git a/2019/20.cpp b/2019/20.cpp index 638f298..811fb55 100644 --- a/2019/20.cpp +++ b/2019/20.cpp @@ -75,7 +75,6 @@ auto FindPortals(Map const& map) -> Portals { auto FindDistancesFrom( Map const& map, std::map const& names, - Distances & distances, std::string const start_name, Coord const start ) { @@ -123,7 +122,7 @@ auto FindDistances(Map const& map, Portals const& portals) { } for (auto const& [start_name, start_coord] : portals) { - distances[start_name] = FindDistancesFrom(map, names, distances, start_name, start_coord); + distances[start_name] = FindDistancesFrom(map, names, start_name, start_coord); } return distances; @@ -144,12 +143,12 @@ auto SolveMaze(Distances const& distances, bool const recursive) -> std::int64_t todo.emplace(0, 0, "-AA"); while(!todo.empty()) { - auto const [steps, depth, name] = todo.top(); + auto const& [steps, depth, name] = todo.top(); todo.pop(); if (name == "-ZZ") { return steps; } if (seen.emplace(depth, name).second) { if (auto const it = distances.find(name); it != distances.end()) { - for (auto const [next, cost] : it->second) { + for (auto const& [next, cost] : it->second) { if (next == "-ZZ") { if (depth == 0) todo.emplace(steps + cost, depth, "-ZZ"); } else { diff --git a/2019/23.cpp b/2019/23.cpp index 75560a3..3f378dd 100644 --- a/2019/23.cpp +++ b/2019/23.cpp @@ -21,7 +21,7 @@ using Machines = std::array; auto BuildNetwork(Machine m) -> Machines { Machines machines; auto& i = std::get(Step(m)).input; - for (i = 0; i < machines.size(); i++) { + for (i = 0; i < std::int64_t(machines.size()); i++) { machines[i] = m; } return machines; diff --git a/2019/24.cpp b/2019/24.cpp index 59be961..f6eddf5 100644 --- a/2019/24.cpp +++ b/2019/24.cpp @@ -22,8 +22,6 @@ using namespace aocpp; namespace { -Coord(* const directions[4])(Coord) = {Up, Down, Left, Right}; - struct Map { std::vector rows; @@ -58,10 +56,10 @@ auto FindBugs(Map const& map) { auto Neighbor1(Coord c) { std::vector result; result.reserve(4); - if (c.x > 0) result.push_back({c.x-1,c.y}); - if (c.x < 4) result.push_back({c.x+1,c.y}); - if (c.y > 0) result.push_back({c.x,c.y-1}); - if (c.y < 4) result.push_back({c.x,c.y+1}); + if (c.x > 0) result.push_back(Left(c)); + if (c.x < 4) result.push_back(Right(c)); + if (c.y > 0) result.push_back(Up(c)); + if (c.y < 4) result.push_back(Down(c)); return result; } @@ -75,7 +73,7 @@ auto Neighbor2(std::pair cd) { result.push_back({{4,yi},d+1}); } } else if (c.x > 0) { - result.push_back({{c.x-1,c.y},d}); + result.push_back({Left(c),d}); } else { result.push_back({{1,2},d-1}); } @@ -85,7 +83,7 @@ auto Neighbor2(std::pair cd) { result.push_back({{0,yi},d+1}); } } else if (c.x < 4) { - result.push_back({{c.x+1,c.y},d}); + result.push_back({Right(c),d}); } else { result.push_back({{3,2},d-1}); } @@ -95,7 +93,7 @@ auto Neighbor2(std::pair cd) { result.push_back({{xi,4},d+1}); } } else if (c.y > 0) { - result.push_back({{c.x,c.y-1},d}); + result.push_back({Up(c),d}); } else { result.push_back({{2,1},d-1}); } @@ -105,7 +103,7 @@ auto Neighbor2(std::pair cd) { result.push_back({{xi,0},d+1}); } } else if (c.y < 4) { - result.push_back({{c.x,c.y+1},d}); + result.push_back({Down(c),d}); } else { result.push_back({{2,3},d-1}); } diff --git a/intcode/src/Parser.cpp b/intcode/src/Parser.cpp index cf489e7..fd5d092 100644 --- a/intcode/src/Parser.cpp +++ b/intcode/src/Parser.cpp @@ -5,7 +5,6 @@ namespace intcode { auto ParseStream(std::istream &in) -> std::vector { - ValueType x; std::string str; std::vector result; while (std::getline(in, str, ',')) {