Solutions for Advent Of Code 2021 written in C
The descriptions of the daily tasks are in the comments in the *.c files (see src/).
The *.txt files in input/ contain the original input for the tasks.
main.exe does all tasks and prints all solutions. It uses the input files in input/.
Use GCC to build main.c with the makefile provided.
| Day | Part 1 | Part 2 |
|---|---|---|
| Day 1 | ⭐ | ⭐ |
| Day 2 | ⭐ | ⭐ |
| Day 3 | ⭐ | ⭐ |
| Day 4 | ⭐ | ⭐ |
| Day 5 | ⭐ | ⭐ |
| Day 6 | ⭐ | ⭐ |
| Day 7 | ⭐ | ⭐ |
| Day 8 | ⭐ | ⭐ |
| Day 9 | ⭐ | ⭐ |
| Day 10 | ⭐ | ⭐ |
| Day 11 | ⭐ | ⭐ |
| Day 12 | ⭐ | ⭐ |
| Day 13 | ⭐ | ⭐ |
| Day 14 | ⭐ | ⭐ |
| Day 15 | ⭐ | ⭐ |
| Day 16 | ⭐ | ⭐ |
| Day 17 | ⭐ | ⭐ |
| Day 20 | ⭐ | ⭐ |
| Day 21 | ⭐ | ⭐ |
| Day 22 | ⭐ | ⭐ |
| Day 24 | ⭐ | ⭐ |
| Day 25 | ⭐ |
Done with hyperfine (see file benchmark.bat)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
benchmark\adv1.exe | 9.0 ± 0.7 | 8.2 | 12.3 | 1.09 ± 0.13 |
benchmark\adv2.exe | 9.7 ± 0.9 | 8.4 | 14.8 | 1.18 ± 0.16 |
benchmark\adv3.exe | 9.1 ± 1.0 | 7.7 | 13.2 | 1.10 ± 0.16 |
benchmark\adv4.exe | 13.2 ± 1.3 | 11.5 | 19.6 | 1.59 ± 0.22 |
benchmark\adv5.exe | 16.1 ± 1.4 | 14.7 | 23.9 | 1.95 ± 0.25 |
benchmark\adv6.exe | 8.3 ± 0.8 | 6.7 | 12.8 | 1.00 |
benchmark\adv7.exe | 12.9 ± 2.6 | 9.2 | 20.4 | 1.56 ± 0.35 |
benchmark\adv8.exe | 12.1 ± 1.5 | 9.4 | 17.0 | 1.46 ± 0.23 |
benchmark\adv9.exe | 14.3 ± 1.9 | 11.1 | 24.9 | 1.72 ± 0.28 |
benchmark\adv10.exe | 11.2 ± 1.5 | 8.8 | 14.9 | 1.36 ± 0.22 |
benchmark\adv11.exe | 11.4 ± 1.2 | 9.2 | 16.8 | 1.38 ± 0.19 |
benchmark\adv12.exe | 100.6 ± 6.0 | 90.3 | 113.0 | 12.16 ± 1.38 |
benchmark\adv13.exe | 21.9 ± 2.0 | 18.5 | 30.4 | 2.64 ± 0.35 |
benchmark\adv14.exe | 16.5 ± 6.9 | 9.3 | 38.7 | 1.99 ± 0.85 |
- Install Mingw
- Add
C:\MinGW\binto PATH - Symlink
mklink C:\MinGW\bin\make.exe C:\MinGW\bin\mingw32-make.exe - In SublimeText Tools > Build System > New Build System...
- Add the following code (also found in Make_AOC.sublime-build)
{ "shell_cmd": "make", "working_dir": "${folder}", "variants": [ { "name": "Run", "shell_cmd": "make && ${folder}/main.exe skip" }, { "name": "Clean", "shell_cmd": "make clean" } ] }
- Save to
C:\Users\[$user]\AppData\Roaming\Sublime Text 3\Packages\User
- Add the following code (also found in Make_AOC.sublime-build)
- Select this Build System in Tools > Build System
- Build with Ctrl + B
- Ctrl + Shift + B to choose variant (e.g run)
All solutions have the same base structure.
There is a snippet for SublimeText to generate this basic structure.
Just type AOC and hit Tab to insert the basic code.
To use it, place AOC.sublime-snippet in C:\Users\<UserName>\AppData\Roaming\Sublime Text 3\Packages\User
Auto-generate a release with the workflow found in .github/workflows/
git tag -a v* -m "My_Msg" git push --tags To solve puzzles, put the input data given by the calendar in a txt file for each day(e.g. 3.txt for Day 3).
Place the txt files in an fodler called input. The folder must be under the same path as the main executeable.
The same can be done for the samples of each puzzle in a folder named samples.
run main to solve the puzzles with the data from input folder.
run main sample to solve the puzzles with the data from samples folder.