Compare commits

..

2 Commits

  1. 12
      src/days/12/Day12.cpp
  2. 1
      src/days/12/Day12.h
  3. 5
      src/main.cpp
  4. 7
      src/util.h

@ -61,8 +61,8 @@ map<Day12::Vertex, uint64> Day12::dijkstra(Graph &graph, Vertex start) {
queue.erase(u); queue.erase(u);
for (const Vertex &v : queue){ for (const Vertex &v : graph.out[u]){
if (!graph.E.contains({u, v})) if (!queue.contains(v))
continue; continue;
size_t newDist = dist[u] + 1; size_t newDist = dist[u] + 1;
@ -100,10 +100,14 @@ Day12::Graph Day12::parseGraph(bool reverse) {
auto checkEdges = [&g, readChar, this](Vertex v1, Vertex v2){ auto checkEdges = [&g, readChar, this](Vertex v1, Vertex v2){
char c1 = readChar(input[v1.second][v1.first]); char c1 = readChar(input[v1.second][v1.first]);
char c2 = readChar(input[v2.second][v2.first]); char c2 = readChar(input[v2.second][v2.first]);
if (c2 <= c1 + 1) if (c2 <= c1 + 1){
g.E.insert({v1, v2}); g.E.insert({v1, v2});
if (c1 <= c2 + 1) g.out[v1].insert(v2);
}
if (c1 <= c2 + 1) {
g.E.insert({v2, v1}); g.E.insert({v2, v1});
g.out[v2].insert(v1);
}
}; };
for (Vertex v : g.V){ for (Vertex v : g.V){

@ -10,6 +10,7 @@ class Day12 : public Day {
struct Graph { struct Graph {
set<Vertex> V; set<Vertex> V;
set<Edge> E; set<Edge> E;
map<Vertex, set<Vertex>> out;
}; };
map<Day12::Vertex, uint64> dijkstra(Graph&,Vertex); map<Day12::Vertex, uint64> dijkstra(Graph&,Vertex);

@ -30,7 +30,10 @@ Input getInput(int day, string key, bool useTestInput, int testFetchIndex) {
string res = cpr::Get(cpr::Url{url}).text; string res = cpr::Get(cpr::Url{url}).text;
size_t i1 = findAll(res, "<code>")[testFetchIndex]; size_t i1 = findAll(res, "<code>")[testFetchIndex];
size_t i2 = findAll(res, "</code>")[testFetchIndex]; size_t i2 = findAll(res, "</code>")[testFetchIndex];
file << res.substr(i1 + 6, i2 - (i1 + 6)); string codeContent = res.substr(i1 + 6, i2 - (i1 + 6));
removeAll(codeContent, "<em>");
removeAll(codeContent, "</em>");
file << codeContent;
file.close(); file.close();
} }
} }

@ -31,3 +31,10 @@ inline vector<size_t> findAll(const string& data, const string& toSearch){
return indices; return indices;
} }
inline void removeAll(string& data, const string& toRemove) {
vector<size_t> indices = findAll(data, toRemove);
std::sort(indices.rbegin(), indices.rend());
for (size_t &i : indices)
data.erase(i, toRemove.size());
}
Loading…
Cancel
Save