[][src]Struct aoc_helper::AocDay

pub struct AocDay<T> { /* fields omitted */ }

The AocDay struct stores information for an aoc day.

You can provide an optional serializer function to serialize the input data into a custom type. The serializer, and the solver functions if you're not using a custom serializer function, take Strings as input.

Methods

impl AocDay<String>[src]

pub fn new(year: i32, day: u8) -> Self[src]

Create a new AocDay instance for the provided year and day.

Example

use aoc_helper::AocDay;

// Create a new AocDay instance for day 12 of aoc 2015
let day_12 = AocDay::new(2015, 12);

impl<T> AocDay<T>[src]

pub fn new_with_serializer(
    year: i32,
    day: u8,
    serializer: fn(_: String) -> T
) -> Self
[src]

Create a new AocDay instance for the provided year and day, with a custom serializer function.

Example

use aoc_helper::AocDay;

let day_2 = AocDay::new_with_serializer(2017, 2, |input| input.split_whitespace().collect::<Vec<_>>());

pub fn input(&mut self, input_path: &str)[src]

Provide a custom input file

Example

use aoc_helper::AocDay;

let mut day_2 = AocDay::new(2017, 2);
day_2.input("path/to/my/input/file.txt");

pub fn with_input(self, input_path: &str) -> Self[src]

Chainable version of AocDay::input()

Example

use aoc_helper::AocDay;

let day_2 = AocDay::new(2017, 2)
    .with_input("path/to/my/input/file.txt");

pub fn session_id(&mut self, session_id: &str)[src]

Provide the session ID

Example

use aoc_helper::AocDay;

let mut day_8 = AocDay::new(2015, 8);
day_8.session_id("82942d3671962a9f17f8f81723d45b0fcdf8b3b5bf6w3954f02101fa5de1420b6ecd30ed550133f32d6a5c00233076af");

pub fn with_session_id(self, session_id: &str) -> Self[src]

Chainable version of AocDay::session_id()

Example

use aoc_helper::AocDay;

let date_8 = AocDay::new(2015, 8)
    .with_session_id("82942d3671962a9f17f8f81723d45b0fcdf8b3b5bf6w3954f02101fa5de1420b6ecd30ed550133f32d6a5c00233076af");

pub fn test(&self, puzzle: &Puzzle<T, impl Display>)[src]

Run a solver function on some example inputs. The function and the inputs should be provided using a Puzzle instance.

Example

use aoc_helper::{AocDay, Puzzle};

let day_5 = AocDay::new(2019, 5);
day_5.test(
    &Puzzle::new(1, |x: String| x.chars().filter(|&y| y == 'z').count())
        .with_examples(&["test", "cases"])
);

pub fn run(
    &mut self,
    puzzle: &Puzzle<T, impl Display>
) -> Result<(), Box<dyn Error>>
[src]

Run a solver function on the day's input. The function should be provided using a Puzzle instance.

Example

use aoc_helper::{AocDay, Puzzle};

let mut day_5 = AocDay::new(2019, 5);
let part_1 = Puzzle::new(
        1,
        |x: String| x.chars().filter(|&y| y == 'z').count()
    )
    .with_examples(&["foo", "bar", "baz"]);
let part_2 = Puzzle::new(
        2,
        |x: String| x.chars().filter(|&y| y != 'z').count()
    )
    .with_examples(&["fubar", "bazz", "fubaz"]);
day_5.test(&part_1);
day_5.test(&part_2);
day_5.run(&part_1);
day_5.run(&part_2);

Auto Trait Implementations

impl<T> RefUnwindSafe for AocDay<T>

impl<T> Send for AocDay<T>

impl<T> Sync for AocDay<T>

impl<T> Unpin for AocDay<T>

impl<T> UnwindSafe for AocDay<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.