A robust, automated starting point for Advent of Code solutions in C++ and Rust.
This template provides a "batteries-included" engine to manage multiple years of puzzles, automatically download inputs, and generate boilerplate code so you can focus strictly on solving the problems.
- Multi-Language: Supports C++20 (CMake) and Rust (Cargo).
- Multi-Year: Scalable folder structure (e.g.,
aoc-2024/,aoc-2025/). - Automation:
- Generates daily boilerplate code (
dayXX.cpp/dayXX.rs). - Downloads puzzle inputs automatically.
- Puzzle Viewer: Downloads and converts puzzle HTML to Markdown for offline reading.
- Generates daily boilerplate code (
- Privacy: Configured
.gitignoreto prevent accidental committing of puzzle inputs or session cookies.
Click the Use this template button at the top of this page to create your own repository.
To enable the automated downloader, you need your Advent of Code session cookie.
- Log in to Advent of Code.
- Open Browser DevTools (F12) -> Application (or Storage) -> Cookies.
- Copy the value of the
sessioncookie. - In your project root, rename the example file and paste your cookie:
cp .env.example .env # Open .env and paste: SESSION=your_cookie_string_here
Run the generator script to set up a specific day.
# Make scripts executable (first time only)
chmod +x new_day.sh get_input.sh
# Generate files for Year 2025, Day 1
./new_day.sh 2025 1This template relies on two Bash scripts to manage the workflow. Here is exactly how to use them.
This is the main entry point. You run this once per day to initialize your environment.
Usage:
./new_day.sh <year> <day>What it does:
- Directory Creation: Creates
aoc-<year>/structure if it doesn't exist. - Project Init:
- C++: Creates
CMakeLists.txtand adds the new executable entry. - Rust: Creates
Cargo.toml.
- C++: Creates
- Code Generation:
- Creates
dayXX.cppwith input reading boilerplate. - Creates
dayXX.rswith input reading boilerplate. - Note: If the source files already exist, it skips them to prevent overwriting your work.
- Creates
- Downloads: Calls
get_input.shto fetch the puzzle data.
Example:
# Setup for December 2nd, 2025
./new_day.sh 2025 2This script fetches data from the Advent of Code servers. It is called automatically by new_day.sh, but you can use it manually if you need to re-download data or if you deleted your inputs.
Usage:
./get_input.sh <day> # Assumes default year (2025)
./get_input.sh <year> <day> # Specific yearFeatures:
- Input File: Downloads your specific input to
aoc-<year>/input/dayXX.txt. - Puzzle Text: Downloads the puzzle HTML, parses it using Python, and converts it to readable Markdown at
aoc-<year>/puzzles/dayXX.md. - Caching: It checks if files already exist before downloading to save Advent of Code server bandwidth.
Dependencies:
curl: Used to fetch data.python3: Used to parse the HTML puzzle description into Markdown.
The template starts clean. As you generate days, the structure grows automatically:
advent-of-code/
├── .env # Session cookie (Local only - DO NOT COMMIT)
├── new_day.sh # Generator script
├── get_input.sh # Downloader script
├── aoc-2025/ # Created automatically
│ ├── input/ # Inputs (ignored by git)
│ ├── puzzles/ # Puzzle text (ignored by git)
│ ├── cpp/ # C++ Project
│ │ ├── CMakeLists.txt
│ │ └── src/day01.cpp
│ └── rust/ # Rust Project
│ ├── Cargo.toml
│ └── src/bin/day01.rs
└── aoc-2024/ # Support for previous years...
Rust solutions are structured as a single workspace per year, with each day being a unique binary.
-
Navigate to the year:
cd aoc-2025/rust -
Run the solution:
# Run Day 1 (Uses default input) cargo run --bin day01 # Run with custom input cargo run --bin day01 ../input/example.txt
C++ solutions use a standard CMake workflow.
-
Navigate to the year:
cd aoc-2025/cpp -
Configure & Build (Only needed once or when adding new days):
mkdir -p build cd build cmake .. make -
Run the solution: Note: Run from the
cpproot (parent of build) to ensure relative paths work.cd .. ./build/day01 # Run with custom input ./build/day01 ../input/example.txt
Script Permission Denied
If you get permission denied, make the scripts executable:
chmod +x *.shSession Cookie Error
If the script says Error: SESSION cookie not found, ensure you have created a file named .env in the root folder and it contains exactly SESSION=....
Download Failed (400/404/500)
- Check if your session cookie is expired (log out and log in again on the website).
- Ensure the puzzle has actually unlocked (EST timezone).
- Check if the Year/Day arguments are correct.
- Template: This template code is open source (MIT). Feel free to use it, fork it, and modify it.
- Advent of Code: Puzzle inputs and descriptions are the intellectual property of Advent of Code. This template is configured to not commit those files to version control by default, respecting the creator's request.
Please visit Advent of Code to support the creator, Eric Wastl.