Advent of Code 2025 - December 8th

Published: (December 9, 2025 at 07:11 AM EST)
2 min read
Source: Dev.to

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!

Back to Blog

Related posts

Read more »

Monkey Market

Part 1 Another math gauntlet I get to program a bunch of math operations. Some will be part of several conditionals. I've done it before. I'm confident I can d...

Advent of Code 2025 - Day 6

Check out my full solution for day 6 on GitHub. Part one The first part gives us a few rows of numbers and a last line with operations that are either addition...