Solutions for Advent of Code in Rust.
| Day | Part 1 | Part 2 |
|---|---|---|
| Day 1 | ⭐ | ⭐ |
| Day 2 | ⭐ | ⭐ |
| Day 3 | ⭐ | ⭐ |
| Day 4 | ⭐ | ⭐ |
| Day 5 | ⭐ | ⭐ |
| Day 6 | ⭐ | ⭐ |
| Day 7 | ⭐ | ⭐ |
| Day 8 | ⭐ | ⭐ |
| Day 9 | ⭐ |
| Day | Part 1 | Part 2 |
|---|---|---|
| Day 1 | 114.2µs |
119.1µs |
| Day 2 | 137.7ms |
110.4ms |
| Day 3 | 32.3µs |
101.8µs |
| Day 4 | 1.0ms |
29.4ms |
| Day 5 | 1.0ms |
957.7µs |
| Day 6 | 61.0µs |
281.3µs |
| Day 7 | 2.9ms |
- |
Total: 284.07ms
# example: `cargo scaffold 1`
cargo scaffold <day>Individual solutions live in the ./src/bin/ directory as separate binaries. Inputs and examples live in the the ./data directory.
Every solution has tests referencing its example file in ./data/examples. Use these tests to develop and debug your solutions against the example input. In VS Code, rust-analyzer will display buttons for running / debugging these unit tests above the unit test blocks.
Tip
If a day has multiple example inputs, you can use the read_file_part() helper in your tests instead of read_file(). If this e.g. applies to day 1, you can create a second example file 01-2.txt and invoke the helper like let result = part_two(&advent_of_code::template::read_file_part("examples", DAY, 2));. This supports an arbitrary number of example files.
# example: `cargo download 1`
cargo download <day># example: `cargo solve 01`
cargo solve <day>Append the --submit <part> option to the solve command to submit your solution for checking.
This runs all solutions sequentially and prints output to the command-line. Same as for the solve command, the --release flag runs an optimized build.
cargo all# example: `cargo time 8 --store`
cargo time <day> [--all] [--store]To run tests for a specific day, append --bin <day>, e.g. cargo test --bin 01. You can further scope it down to a specific part, e.g. cargo test --bin 01 part_one.
cargo testcargo fmtcargo clippyIf you are not only interested in the runtime of your solution, but also its memory allocation profile, you can use the template's DHAT integration to analyze it. In order to activate DHAT, call the solve command with the --dhat flag.
cargo solve 1 --dhat
# output:
# Running `target/dhat/1`
# dhat: Total: 276 bytes in 3 blocks
# dhat: At t-gmax: 232 bytes in 2 blocks
# dhat: At t-end: 0 bytes in 0 blocks
# dhat: The data has been saved to dhat-heap.json, and is viewable with dhat/dh_view.html
# Part 1: 9001 (4.1ms)The command will output some basic stats to the command-line and generate a dhat-heap.json report in the repo root directory.
You can pass the report a tool like dh-view to view a detailed breakdown of heap allocations.
- itertools: Extends iterators with extra methods and adaptors. Frequently useful for aoc puzzles.
- regex: Official regular expressions implementation for Rust.
A curated list of popular crates can be found on blessed.rs.
Do you have aoc-specific crate recommendations? Share them!
