Helper crate for solving the Advent of Code.
Your main.rs
should look like the following:
aoc_helper::main!($YEAR =>
day1,
day2,
// ...
);
Here $YEAR
is the year of the AoC you will be solving in this crate. There's no support for multiple years in the same crate.
day1
, day2
ecc ecc are the days you've solved. Each day must be solved in a dayN
module which exposes the following functions:
pub fn input_generator(input: &str) -> Input
where:input
is the trimmed version of the input file contentsInput
can be a custom type as long as it's consistent inside the same day moduleInput
can borrowinput
pub fn part1(input: &Input) -> Part1Answer
where:Input
should be the same as theinput_generator
one- Technically you could swap it with any type that can be deref coerced from
&Input
, however it's preferred to keep&Input
for faster typing and more uniform solutions. It's suggested to add#![allow(clippy::ptr_arg)]
tomain.rs
to silence possible warnings derived from this.
- Technically you could swap it with any type that can be deref coerced from
Part1Answer
is any type that implementsDisplay
pub fn part2(input: &Input) -> Part2Answer
where:&Input
has the same restrictions as inpart1
Part2Answer
is any type that implementsDisplay
- It's not required for
day25
, in which case it will be ignored if present.
You can have the macro setup each dayN.rs
by running the following command:
cargo run -- setup $DAY
The module structure is hardcoded in this library and can't be customized in any way other than forking the library itself. This is the price for having a fast declarative macro doing all the work for you.
This crate offers an opinionated prelude which is also re-exported when calling the main!
macro. You can find it in src/prelude.rs
Find your session token for the AoC. You'll need to visic adventofcode.com open the devtools of your browser, then:
- Firefox: "Storage" tab, "Cookies" folder, and copy the "Value" field of the "session" cookie.
- Google Chrome / Chromium: "Application" tab, "Cookies" folder, and copy the "Value" field of the "session" cookie.
Then run the following command:
cargo run -- session $SESSION
cargo run --release
Note: this will download the input file if it's missing
cargo run --release -- -d $DAY
Note: this will download the input file if it's missing
cargo run --release -- -d all
Note: this will download all the missing input files
cargo run -- input
cargo run -- input -d all
cargo run -- input -d $DAY