Advent of Code 2025 - December 8th
Source: Dev.to
Puzzle Overview
The day 8 puzzle was brutal—no exaggeration. I missed the deadline of completing the puzzle on the same day it was released.
Graph Approach
My pitfall for this puzzle: a graph approach was the only way I could think of, but graph code tends to be verbose (at least the way I write it), and that pushed me well over 100 lines. For part two I also resorted to a manual binary search 😳.
Solution Code
Part One
#include
#include
#include
#include
#include
#include
#include
#include
struct Node {
int x, y, z;
bool operator==(const Node &other) const {
return x == other.x && y == other.y && z == other.z;
}
bool operator nodes;
std::vector edges;
};
double distance(const Node &a, const Node &b) {
return std::sqrt(std::pow(a.x - b.x, 2) +
std::pow(a.y - b.y, 2) +
std::pow(a.z - b.z, 2));
}
Graph loadInput(const std::string &filename) {
Graph graph;
std::ifstream file(filename);
std::string line;
while (std::getline(file, line)) {
auto firstComma = line.find(',');
auto secondComma = line.find(',', firstComma + 1);
int x = std::stoi(line.substr(0, firstComma));
int y = std::stoi(line.substr(firstComma + 1,
secondComma - firstComma - 1));
int z = std::stoi(line.substr(secondComma + 1));
graph.nodes.push_back(Node{x, y, z});
}
for (size_t i = 0; i &edges,
const Node &node,
std::set &visited) {
if (visited.find(node) != visited.end())
return 0;
visited.insert(node);
int count = 1;
for (const auto &edge : edges) {
if (*edge.from == node && visited.find(*edge.to) == visited.end()) {
count += walk(edges, *edge.to, visited);
} else if (*edge.to == node && visited.find(*edge.from) == visited.end()) {
count += walk(edges, *edge.from, visited);
}
}
return count;
}
void partOne() {
auto distanceGraph = loadInput("/Users/rob/projects/robvanderleek/adventofcode/2025/08/input.txt");
constexpr int numberOfConnections = 1000;
std::vector edges;
edges.reserve(numberOfConnections);
for (int i = 0; i visited;
std::vector circuits;
for (const auto &node : distanceGraph.nodes) {
auto count = walk(edges, node, visited);
if (count > 0)
circuits.push_back(count);
}
std::sort(circuits.begin(), circuits.end(),
[](int a, int b) { return a > b; });
unsigned long result = 1;
for (int i = 0; i edges;
edges.reserve(5601);
for (int i = 0; i visited;
assert(walk(edges, distanceGraph.nodes[0], visited) == 1000);
Edge edge = edges.back();
long result = edge.from->x * edge.to->x;
std::cout << result << std::endl;
assert(result == 1131823407);
}
int main() {
partOne();
partTwo();
return 0;
}
That’s it! See you again tomorrow!