Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rossmacarthur/advent
🎄 My Advent of Code solutions
https://github.com/rossmacarthur/advent
advent-of-code rust
Last synced: 4 days ago
JSON representation
🎄 My Advent of Code solutions
- Host: GitHub
- URL: https://github.com/rossmacarthur/advent
- Owner: rossmacarthur
- License: apache-2.0
- Created: 2020-12-01T06:06:56.000Z (almost 4 years ago)
- Default Branch: trunk
- Last Pushed: 2023-12-23T17:04:21.000Z (11 months ago)
- Last Synced: 2024-10-14T11:21:51.135Z (22 days ago)
- Topics: advent-of-code, rust
- Language: Rust
- Homepage:
- Size: 3.69 MB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# advent
[![Build Status](https://github.com/rossmacarthur/advent/actions/workflows/build.yaml/badge.svg)](https://github.com/rossmacarthur/advent/actions/workflows/build.yaml)
My 🎅 [Advent of Code](https://adventofcode.com) solutions. Includes a runner
and benchmarker with free Christmas trees 🎄.## Getting started
The following commands use a Cargo alias `cargo advent` defined in
`.cargo/config.toml` to run the solutions. 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](https://www.reddit.com/r/adventofcode/wiki/faqs/automation).```sh
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 will be built using `--release`.
### New solutions
Use the following to add a [template](./crates/cli/src/template.rs) 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
```## Using the runner/benchmarker
You can use the provided runner and benchmarker for your own solutions. To get
started simply add the crate to the Cargo manifest for your solution.```toml
[dependencies]
advent = { git = "https://github.com/rossmacarthur/advent" }
```Then use the following as your main function.
```rust
fn main() {
let solution = advent::new(parse_input).part(part1).part(part2).build();
solution.cli()
}
```**Where**
- `parse_input` is a function that returns any type `I` implementing `Clone`.
- Each part function takes `I` as an argument and returns something implementing
`Display`.Finally, `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.That's all! You're free to structure your program however else you want. See
[template.rs](./crates/cli/src/template.rs) for the template I use or any of the
solutions in this crate for an example.Run and benchmark output:
### Features
There are also some optional features which pull in some other crates.
- **`festive`** enables some festive ascii art and changes the default output to
`--output festive`
- **`json`** supports JSON output using `--output json`, useful for collecting
benchmark information
- **`prelude`** re-exports my prelude crate that can be imported using
```rust
use advent::prelude::*;
```They can be enabled in your Cargo manifest like this:
```toml
[dependencies]
advent = { git = "https://github.com/rossmacarthur/advent", features = ["festive", "json"] }
```## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)at your option.