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) -> Inputwhere:inputis the trimmed version of the input file contentsInputcan be a custom type as long as it's consistent inside the same day moduleInputcan borrowinput
pub fn part1(input: &Input) -> Part1Answerwhere:Inputshould be the same as theinput_generatorone- Technically you could swap it with any type that can be deref coerced from
&Input, however it's preferred to keep&Inputfor faster typing and more uniform solutions. It's suggested to add#![allow(clippy::ptr_arg)]tomain.rsto silence possible warnings derived from this.
- Technically you could swap it with any type that can be deref coerced from
Part1Answeris any type that implementsDisplay
pub fn part2(input: &Input) -> Part2Answerwhere:&Inputhas the same restrictions as inpart1Part2Answeris 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 $DAYThe 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 $SESSIONcargo run --releaseNote: this will download the input file if it's missing
cargo run --release -- -d $DAYNote: this will download the input file if it's missing
cargo run --release -- -d allNote: this will download all the missing input files
cargo run -- inputcargo run -- input -d allcargo run -- input -d $DAY