6 releases

0.2.1 Dec 24, 2019
0.2.0 Dec 22, 2019
0.1.3 Dec 18, 2019

#39 in #aoc

MIT license

19KB
224 lines

AOC Helper documentation

rustc 1.40.0 crates.io 0.2.0 license

AOC Helper is a crate to make solving and sharing aoc problems in rust easier. It is inspired by cargo-aoc. cargo-aoc is a binary that will also take care of compilation, while this crate is a library you can import and use in your code. This aims to make it easier to share and debug other people's code, and to perhaps be easier to set up.

For more examples, check out the examples directory in the repository.

Usage

To get started, add aoc-helper to the dependencies section in your Cargo.toml:

[dependencies]
aoc-helper = "0.2.1"

You also need to provide a session ID for aoc-helper to be able to download your input files. The session ID is stored in a cookie called session in your browser on the aoc website if you're logged in. You can provide the session ID through an environment variable with the name AOC_SESSION_ID, through the session_id functions on Helper, or by using an aoc_helper.toml file.

If you're using an aoc_helper.toml file, you need to specify the config-file feature and specify your session ID in aoc_helper.toml like this:

session-id = "82942d3671962a9f17f8f81723d45b0fcdf8b3b5bf6w3954f02101fa5de1420b6ecd30ed550133f32d6a5c00233076af"

Then, create an instance of AocDay. Look at its documentation for information. The output is by default colored. You can disable this by disabling the default features.

Example

use aoc_helper::{AocDay, Puzzle};

fn main() {
    // Create a new `AocDay` instance for day 1 of 2015
    // Note: this is not the actual problem from day 1 of 2015
    let mut day_1 = AocDay::new(2015, 1);

    // Create a new `Puzzle` instance for part 2
    let part_2 = Puzzle::new(
        2,
        |x: String| x.lines().filter(|&y| y.contains("foo")).count()
        )
        .with_examples(&["random\nstuff\nfoo\nbaz", "foo\nbar\ntest\ncases"]);

    // Run the solver functions on the example cases
    day_1.test(&part_2);
    // Run the solver functions on the day's input
    day_1.run(&part_2).unwrap();
}

Dependencies

~4–12MB
~137K SLoC