Skip to content

๐ŸŽ„ My Advent of Code solutions

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

rossmacarthur/advent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

advent

Build Status

My ๐ŸŽ… Advent of Code solutions. Includes a runner and benchmarker with free Christmas trees ๐ŸŽ„.

image

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.

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 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.

[dependencies]
advent = { git = "https://github.com/rossmacarthur/advent" }

Then use the following as your main function.

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 for the template I use or any of the solutions in this crate for an example.

Run and benchmark output:

screenshot of run output

screenshot of bench 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
    use advent::prelude::*;

They can be enabled in your Cargo manifest like this:

[dependencies]
advent = { git = "https://github.com/rossmacarthur/advent", features = ["festive", "json"] }

License

Licensed under either of

at your option.

About

๐ŸŽ„ My Advent of Code solutions

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Languages