My π Advent of Code solutions. Includes a runner and benchmarker with free Christmas trees π.
You can use the runner and benchmarker in this repository for your own solutions. To get started simply add the crate to the Cargo manifest for your solution.
[dependencies]
advent = { git = "https://github.com/rossmacarthur/advent", tag = "0.2.0" }Then use the following as your main function.
fn main() {
let solution = advent::new(|| {
// parse input, return impl Clone
})
.part(|input| {
// part 1 solution using input, return impl Display
})
.part(|input| {
// part 2 solution using input, return impl Display
})
.build();
solution.cli()
}cli() will instantiate a command line interface and run the program. Ordinary
runs will run each part once and output the answers. Passing --bench to the
program will perform a benchmark. Pass --help to see other options.
That's all! You're free to structure your program however else you want. See template.rs for the template I use or any of the solutions in this crate for an example.
Run and benchmark output:
There are also some optional features which pull in some other crates.
festiveenables some festive ascii art and changes the default output to--output festivejsonsupports JSON output using--output json, useful for collecting benchmark informationpreludere-exports my prelude crate that can be imported usinguse advent::prelude::*;
They can be enabled in your Cargo manifest like this:
[dependencies]
advent = { git = "https://github.com/rossmacarthur/advent", features = ["festive", "json"] }The following commands use a Cargo alias cargo advent defined in
.cargo/config.toml to run the solutions. No inputs are committed to this repo,
so this tool will automatically fetch the input for the puzzle and cache it
locally when the solution is run for the first time. This requires the
ADVENT_SESSION environment variable to be set. You can find this under the
cookie name "session" in your logged in Advent of Code browser session. This
tool follows the automation guidelines on the /r/adventofcode
wiki.
export ADVENT_SESSION="533..."Solutions can be run using the run command. Just pass in the year and day. For
example, the following will run the solution for 2020 day 18.
cargo advent -y 2020 -d 18 run
Tests can be run using the test subcommand.
cargo advent -y 2020 -d 18 test
Benchmarks can be run using the bench subcommand.
cargo advent -y 2020 -d 18 bench
Extra arguments can be passed to both Cargo and the binary. Arguments after the
first -- argument will be passed to Cargo and arguments after the second --
will be passed to the actual binary. For example if we wanted the JSON output of
the benchmark we could run the following.
cargo advent -y 2020 -d 18 bench -- --features=json -- --output json
All of the above are built using --release.
Use the following to add a template for a new solution.
cargo advent -y 2022 -d 1 new
Open the browser for the given problem
cargo advent -y 2020 -d 7 open
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.