Skip to content

michaeladler/aoc-2023

Repository files navigation

ci

🎄 Advent of Code 2023 Solutions 🎄

Welcome to my repository where I share my solutions to the Advent of Code 2023 challenges, tackled using the good old C programming language. Advent of Code is an annual December event where programmers solve fun, holiday-themed puzzles.

🛠 Usage

Each puzzle solution is compiled into its own standalone executable, named in accordance with its corresponding day. For instance, the executable for the first puzzle is day01. By default, these executables search for their respective input files located at input/dayXX.txt, where XX represents the two-digit day number (e.g., 01 for Day 1). Alternatively, you have the option to provide input via a command-line argument. For example, you can run ./day01 mine.txt to specify a different input file.

🏗 Building and Running Tests

Each puzzle in this repository is accompanied by tests, which are designed using both the examples provided in the puzzle and the actual input.txt file. Since sharing the puzzle input data is discouraged, the inputs have been encrypted.

Note: Tests using the actual input.txt have to be enabled at compile time with the -Dhave-inputs=true option (this only make sense if you have my input.txt files since your answers will differ from mine).

Release Build

meson setup --buildtype=release -Db_lto=true -Dhave-inputs=true build
ninja -C build test

Debug Build

meson setup --buildtype=debugoptimized -Db_sanitize=address -Db_lundef=false -Dhave-inputs=true build_debug
ninja -C build_debug test

⏱ Performance Benchmarks

The solutions were tested on different processors using hyperfine and/or poop. Compiled using clang 16 and LTO.

Day Intel i7-11850H AMD Ryzen 5 PRO 4650U
1 276 µs 520 µs
2 185 µs 434 µs
3 231 µs 501 µs
4 368 µs 679 µs
5 1.4 s 2.6 s
6 200 µs 472 µs
7 2.6 ms 3.54 ms
8 462.4 µs 1 ms
9 256 µs 464 µs
10 5.8 ms 16.4 ms
11 980 µs 1.7 ms
12 347 ms 554 ms
13 248 µs 486 µs
14 44 ms 53.4 ms
15 1.1 ms 1 ms
16 34.4 ms 33.5 ms
17 315.3 ms 604 ms
18 173 µs 379 µs
19 422 µs 891 µs
19 16.8 ms

🙏 Acknowledgments and Resources

Special thanks to the authors of these very useful C resources:

  • Cauldron - A collection of useful C code snippets and utilities.
  • C Algorithms - A library of common data structures and algorithms written in C.
  • CTL - A library for container types for C.
  • CTest - A unit testing framework for C.
  • Log.c - A simple logging library implemented in C.
  • Sort - A collection of sorting algorithms implemented in C.
  • str - yet another string library for C language.
  • xxhash - Extremely fast non-cryptographic hash algorithm.
  • slice99 - Memory slices for C99.