Skip to content

timvisee/advent-of-code-2021

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Advent of Code 2021 in Rust

My Advent of Code 2021 solutions in the Rust programming language. This repository holds a separate Rust project for each day and part.

I attempt to develop a standalone, elegant, compact and fast solution for each problem (two each day).

Previous year I did the same, solving everything in under a second:

Timings

Here is how long each solution runs. All solutions are measured (non scientifically) in bench.rs on an AMD Ryzen 9 5900X (24) @ 3.7GHz machine running Linux.

part A part B
day 1 0.025ms 0.024ms
day 2 0.024ms 0.025ms
day 3 0.021ms 0.023ms
day 4 0.075ms 0.106ms
day 5 0.110ms 0.220ms
day 6 0.0027ms 0.0028ms
day 7 0.013ms 0.013ms
day 8 0.008ms 0.026ms
day 9 0.012ms 0.036ms
day 10 0.011ms 0.015ms
day 11 0.019ms 0.039ms
day 12 0.015ms 0.272ms
day 13 0.038ms 0.044ms
day 14 0.007ms 0.008ms
day 15 1.05 ms 37.7 ms
day 16 0.002ms 0.007ms
day 17 0.0002ms 0.095ms
day 18 0.141ms 2.61 ms
day 19 1.03 ms 1.03 ms
day 20 0.042ms 3.10 ms
day 21 0.0008ms 0.016ms
day 22 0.083ms 1.74 ms
one-by-one (1 CPU core) parallel
everything 50.36 ms 39.53ms

Run solutions

Each Rust project contains a input.txt file, holding the puzzle input. Simply run the project to see the solution appear.

# Switch to day 1a, and run it
cd day01a
cargo +nightly run --release

# or run everything in parallel
cd ../runner
cargo +nightly run --release --bin runner-par

# or benchmark every day
cd ../runner
cargo +nightly run --release --bin bench

Some solutions require Rust Nightly, that's why +nightly is included.

Other years

License

This project is released under the GNU GPL-3.0 license. Check out the LICENSE file for more information.