warnings
This commit is contained in:
parent
4a8b31bd86
commit
346283bc8a
|
@ -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
|
||||
|
|
|
@ -21,8 +21,8 @@ struct Particle {
|
|||
auto Step(std::vector<Particle> & 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;
|
||||
|
|
16
2019/18.cpp
16
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;
|
||||
|
|
|
@ -75,7 +75,6 @@ auto FindPortals(Map const& map) -> Portals {
|
|||
auto FindDistancesFrom(
|
||||
Map const& map,
|
||||
std::map<Coord, Name> 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 {
|
||||
|
|
|
@ -21,7 +21,7 @@ using Machines = std::array<Machine, 50>;
|
|||
auto BuildNetwork(Machine m) -> Machines {
|
||||
Machines machines;
|
||||
auto& i = std::get<Input>(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;
|
||||
|
|
18
2019/24.cpp
18
2019/24.cpp
|
@ -22,8 +22,6 @@ using namespace aocpp;
|
|||
|
||||
namespace {
|
||||
|
||||
Coord(* const directions[4])(Coord) = {Up, Down, Left, Right};
|
||||
|
||||
struct Map {
|
||||
std::vector<std::string> rows;
|
||||
|
||||
|
@ -58,10 +56,10 @@ auto FindBugs(Map const& map) {
|
|||
auto Neighbor1(Coord c) {
|
||||
std::vector<Coord> 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<Coord, std::int64_t> 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<Coord, std::int64_t> 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<Coord, std::int64_t> 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<Coord, std::int64_t> 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});
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
namespace intcode {
|
||||
|
||||
auto ParseStream(std::istream &in) -> std::vector<ValueType> {
|
||||
ValueType x;
|
||||
std::string str;
|
||||
std::vector<ValueType> result;
|
||||
while (std::getline(in, str, ',')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user