Advent of Code solutions written in C, with a small framework for fetching inputs and timing each part.
- CMake 3.16+
- A C11 compiler (GCC or Clang)
- libcurl (for fetching puzzle inputs)
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build buildThis produces two binaries in build/:
| Binary | Purpose |
|---|---|
aoc |
Run a solution |
fetch_input |
Download a puzzle input from adventofcode.com |
./run.sh <year> <day>run.sh fetches the input automatically if it is not already present, then runs the solution. The build directory defaults to ./build and can be overridden:
BUILD_DIR=/path/to/build ./run.sh 2025 1To run directly:
./build/aoc run 2025 1Create a .env file in the project root with your session cookie:
AOC_SESSION=your_session_cookie_here
Then:
./build/fetch_input 2025 1Inputs are saved to inputs/year<YYYY>/day<DD>.txt.
- Create
src/solutions/year<YYYY>/day<DD>.candday<DD>.hfollowing the pattern inyear2025/day01.*. - Register the function in
src/solutions/year<YYYY>/year<YYYY>.cby appending it to thedays[]array. - Re-run CMake (the build system picks up new
.cfiles viaGLOB_RECURSEautomatically after reconfiguring).
To add a new year, create year<YYYY>.c/year<YYYY>.h and add an entry to the years[] table in src/solutions/solutions.c.
src/
common.c/h — shared utilities (I/O, timing, string helpers)
main.c — entry point
runner.c/h — CLI argument parsing and solution dispatch
fetch_input.c/h — input downloader (libcurl)
fetch_main.c — entry point for fetch_input binary
solutions/
solutions.c/h — year dispatch table
year2025/
year2025.c/h — day dispatch table for 2025
day01.c/h — solution for day 1
inputs/
year2025/
day01.txt — puzzle inputs (not tracked in git)