Skip to content

A robust, automated polyglot template for Advent of Code. Features C++ & Rust boilerplate generation, automatic input downloading, and puzzle text parsing.

Notifications You must be signed in to change notification settings

0bVdnt/advent-of-code-rust-cpp-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎄 Advent of Code Polyglot Template (Rust & C++)

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.

Features

  • 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.
  • Privacy: Configured .gitignore to prevent accidental committing of puzzle inputs or session cookies.

Quick Start

1. Create your Repo

Click the Use this template button at the top of this page to create your own repository.

2. Configure Session

To enable the automated downloader, you need your Advent of Code session cookie.

  1. Log in to Advent of Code.
  2. Open Browser DevTools (F12) -> Application (or Storage) -> Cookies.
  3. Copy the value of the session cookie.
  4. 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

3. Generate a Day

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 1

Detailed Script Usage

This template relies on two Bash scripts to manage the workflow. Here is exactly how to use them.

1. The Generator: ./new_day.sh

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:

  1. Directory Creation: Creates aoc-<year>/ structure if it doesn't exist.
  2. Project Init:
    • C++: Creates CMakeLists.txt and adds the new executable entry.
    • Rust: Creates Cargo.toml.
  3. Code Generation:
    • Creates dayXX.cpp with input reading boilerplate.
    • Creates dayXX.rs with input reading boilerplate.
    • Note: If the source files already exist, it skips them to prevent overwriting your work.
  4. Downloads: Calls get_input.sh to fetch the puzzle data.

Example:

# Setup for December 2nd, 2025
./new_day.sh 2025 2

2. The Downloader: ./get_input.sh

This 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 year

Features:

  • 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.

Project Structure

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...

Running Rust

Rust solutions are structured as a single workspace per year, with each day being a unique binary.

  1. Navigate to the year:

    cd aoc-2025/rust
  2. Run the solution:

    # Run Day 1 (Uses default input)
    cargo run --bin day01
    
    # Run with custom input
    cargo run --bin day01 ../input/example.txt

Running C++

C++ solutions use a standard CMake workflow.

  1. Navigate to the year:

    cd aoc-2025/cpp
  2. Configure & Build (Only needed once or when adding new days):

    mkdir -p build
    cd build
    cmake ..
    make
  3. Run the solution: Note: Run from the cpp root (parent of build) to ensure relative paths work.

    cd ..
    ./build/day01
    
    # Run with custom input
    ./build/day01 ../input/example.txt

Troubleshooting

Script Permission Denied If you get permission denied, make the scripts executable:

chmod +x *.sh

Session 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.

License & Disclaimer

  • 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.

About

A robust, automated polyglot template for Advent of Code. Features C++ & Rust boilerplate generation, automatic input downloading, and puzzle text parsing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages