This is my implementation of the Advent of Code programming challenges in Rust.
Day | Part 1 | Part 2 |
---|---|---|
Day 1 | ⭐ | ⭐ |
Day 2 | ⭐ | ⭐ |
Day 3 | ⭐ | ⭐ |
Day 4 | ⭐ | ⭐ |
Day 5 | ⭐ | ⭐ |
Day 6 | ⭐ | ⭐ |
Day 7 | ⭐ | ⭐ |
Day 8 | ⭐ | ⭐ |
The following benchmarks were created on a Macbook Pro with an M2 Pro processor:
Day | Part 1 | Part 2 |
---|---|---|
Day 1 | 24.2µs |
120.8µs |
Day 2 | 40.9µs |
40.8µs |
Day 3 | 260.7µs |
116.3µs |
Day 4 | 85.2µs |
104.7µs |
Day 5 | 19.5µs |
55.2µs |
Day 6 | 0.21µs |
0.25µs |
Day 7 | 3.87ms |
5.12ms |
Day 8 | 619.5µs |
796.6µs |
This project is organized as a single crate with a different binary for each day and some common helpers to reduce the boilerplate.
data
- Holds data that gets run against the codedata/examples
- Holds the examples that are provided with the challengesdata/examples/xx/part-x.txt
- Since each day has 2 parts, each part is located in a separate file inside a directory for that day. See Example Format.data/inputs/xx.txt
- The input files for each day. See Downloading Input Files.src/lib.rs
- Contains some helper code to reduce boilerplate such as thesolution!
macrosrc/main.rs
- Contains a simple binary to download the input files. See Downloading Input Files.src/bin/xx.rs
- The solution files for each day
Since input files are unique to every user, you need to supply your session token to be able to download the inputs for your account. This can be done through the AOC_SESSION_TOKEN
environment variable.
With your session token in your environment, you can invoke the downloader with:
$ cargo run
To run the solution code for a specific day, all you need to do is supply the correct binary name to cargo:
$ cargo run --bin 01
All the solution files include tests for the provided examples in the prompt. See Example Format for more details. To run the test suite on all the solutions, use:
$ cargo test
And to run the tests for a particular solution, use:
$ cargo test --bin 01
All the example tests also include benchmarks to measure the performance of the solutions. You can run the benchmark suite on all the solutions like this:
$ cargo bench
Or run them for a specific day like this:
$ cargo bench --bin 01
To remove the need for solution files to include tests for the examples, examples for each day are stored in a special format which includes the expected solution, and can easily be parsed by the runner helpers. Example files look like this:
<expected solution>
---
<example input>
For example, Day 1's example for part 1 looks like this:
142
---
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet