Selected Article

Python Advent of Code Template Generator

Posted on: 2025-07-27, Updated on: 2025-07-27 21:09:21 | Read time: 2.1 minutes

Topic(s): programming

After hearing someone casually mention “Christmas in July,” I couldn’t help but think of Advent of Code: the December tradition where thousands of programmers race to solve puzzles at midnight (EST/UTC-5) to earn stars and help Santa’s elves until Christmas. As anyone who's participated in Advent of Code knows, the first few days can be brutally competitive. Leaderboards typically fill up within the first few minutes. With this being the case, I decided to make a tool that could setup a project structure ahead of time to better my chances.

The idea: you run a single Python script, and it sets up everything you need for a full AoC season in your preferred language (C++ by default).

With this tool, you can:

Tool Structure

aoc.py
factories/
├── clj_factory.py
├── cpp_factory.py
└── __init__.py
templates/
├── clj
│   ├── deps.edn.j2
│   ├── .gitignore.j2
│   ├── README.md.j2
│   └── src
│       ├── aoc.clj.j2
│       └── day_xx.clj.j2
└── cpp
    ├── CMakeLists.txt.j2
    ├── main.cpp.j2
    └── Source
        ├── AdventOfCodeStd.cpp.j2
        └── AdventOfCodeStd.hpp.j2

7 directories, 16 files

Example: C++ Factory Template Generation

from jinja2 import Environment, FileSystemLoader

def generate_cpp_template(year: int):
    env = Environment(loader=FileSystemLoader("templates/cpp"))
    template = env.get_template("main.cpp.j2")
    rendered = template.render(year=year, day=1)

    with open(f"{year}/Day01/Part1.cpp", "w") as f:
        f.write(rendered)

Example Usage

  $ ./aoc.py --help
  usage: aoc.py [OPTION(s)]

  Templating tool for Advent of Code.

  options:
    -h, --help       show this help message and exit
    -y, --year YEAR  Year for Advent of Code
    -l, --lang LANG  Programming language (e.g., cpp, python)
    --force          Force overwrite of existing year directory contents
    -v, --version    show program's version number and exit
$
$ ./aoc.py --lang cpp # Generate a C++ template for the current year
$ ./aoc.py --year 2024 --lang clj # Generate a Clojure template for the AoC year 2024

It’s a simple tool, but it’ll definitely make prepping for AoC smoother this year. I hope to extend the tool further to support either of the languages I plan to use for Advent of Code 2025, those being: PowerShell or Python. You can find the script in my Advent of Code GitHub repository. The concerned files and directories are aoc.py, factories/, and templates/. I also host a standalone version of the tool on this site. Check out the links below.

Thanks for reading!

Resources:


Post a Comment

Click to generate a new captcha.

0 Comments