Solutions for Advent of Code in Rust.
Repo created from https://github.com/fspoettel/advent-of-code-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 10 | โญ | โญ |
# example: `cargo scaffold 1`
cargo scaffold <day>
# output:
# Created module "src/bin/01.rs"
# Created empty input file "src/inputs/01.txt"
# Created empty example file "src/examples/01.txt"
# ---
# ๐ Type `cargo solve 01` to run your solution.
Individual solutions live in the ./src/bin/
directory as separate binaries.
Every solution has unit tests referencing its example file. Use these unit tests to develop and debug your solution against the example input. For some puzzles, it might be easier to forgo the example file and hardcode inputs into the tests.
When editing a solution, rust-analyzer
will display buttons for running / debugging unit tests above the unit test blocks.
Note
This command requires installing the aoc-cli crate.
# example: `cargo download 1`
cargo download <day>
# output:
# Downloading input with aoc-cli...
# Loaded session cookie from "/home/felix/.adventofcode.session".
# Downloading input for day 1, 2021...
# Saving puzzle input to "/tmp/tmp.MBdcAdL9Iw/input"...
# Done!
# ---
# ๐ Successfully wrote input to "src/inputs/01.txt"!
To download inputs for previous years, append the --year/-y
flag. (example: cargo download 1 --year 2020
)
Puzzle inputs are not checked into git. Reasoning.
# example: `cargo solve 01`
cargo solve <day>
# output:
# Running `target/debug/01`
# ๐ Part 1 ๐
#
# 6 (elapsed: 37.03ยตs)
#
# ๐ Part 2 ๐
#
# 9 (elapsed: 33.18ยตs)
solve
is an alias for cargo run --bin
. To run an optimized version for benchmarking, append the --release
flag.
Displayed timings show the raw execution time of your solution without overhead (e.g. file reads).
cargo all
# output:
# Running `target/release/advent_of_code`
# ----------
# | Day 01 |
# ----------
# ๐ Part 1 ๐
#
# 0 (elapsed: 170.00ยตs)
#
# ๐ Part 2 ๐
#
# 0 (elapsed: 30.00ยตs)
# <...other days...>
# Total: 0.20ms
all
is an alias for cargo run
. To run an optimized version for benchmarking, use the --release
flag.
Total timing is computed from individual solution timings and excludes as much overhead as possible.
cargo test
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 fmt
cargo clippy