Advent of Code 2025 Day 6— C++
Marketing Pitch and Impressions#
C++ was designed with systems programming and embedded, resource-constrained software and large systems in mind, with performance, efficiency, and flexibility of use as its design highlights. C++ has also been found useful in many other contexts, with key strengths being software infrastructure and resource-constrained applications, including desktop applications, video games, servers (e.g., e-commerce, web search, or databases), and performance-critical applications (e.g., telephone switches or space probes).
C++ is a surprisingly long-lived language having been around for more than 40 years now. It’s core philosophy is to provide developers with maximum degree of control over system resources, including CPU and memory. Unsurprisingly, this level of control comes with significant complexity. One of the often heard maxims in the C++ world is “you only pay for what you use.”
Visual Studio Code support for C++ is excellent, as you might expect.
The Code#
I’ve written quite a bit of C++ code over the years, but I have not used it much recently. I was looking forward to putting the code together for this problem but as it turned out, this was one of the more fiddly problems to solve this year.
The solution makes use of std::ranges and std::views to form a processing
pipeline. I’ve implemented a custom pipeline operator to apply the supply the
applied operation to the provided numbers.
Both part 1 and part 2 are calculated in the same way, but differing orientations. For both parts, columnar boundaries are established. Then part 1 applies the supplied operator to horizontal substrings arranged in rows. Part 2 applies the same operator to vertical substrings arranged in columns.
| |
Install C++ and run#
You need a recent compiler to support the C++23 standard library features.
C++ doesn’t have a standard package manager, so we just compile and execute.
# You probably have this installed already
# Execute the code
g++ -Wall -Wpedantic -std=c++23 -O -o d06 d06.cpp && ./d06