pub struct Puzzle<T, D> { /* private fields */ }
Expand description
The Puzzle
struct stores information for an aoc puzzle. Two puzzles
release each aoc day.
Implementations§
Source§impl<T, D: Display> Puzzle<T, D>
impl<T, D: Display> Puzzle<T, D>
Sourcepub fn new(part: u8, solver: fn(T) -> D) -> Self
pub fn new(part: u8, solver: fn(T) -> D) -> Self
Create a new Puzzle
instance for the provided part number and solver
function.
§Example
use aoc_helper::Puzzle;
let part_1 = Puzzle::new(1, |x| x.lines().count());
Examples found in repository?
examples/2015_day1.rs (lines 25-29)
18fn main() {
19 // NOTE: You need to specify a session ID for this to work
20
21 // Create a new `AocDay` instance for day 1 of aoc 2015
22 let mut day_1 = AocDay::new(2015, 1);
23
24 // Create a new `Puzzle` instance for part 1
25 let part_1 = Puzzle::new(1, |instructions: String| {
26 let mut floor = 0;
27 instructions.chars().for_each(|x| if x == '(' { floor += 1 } else { floor -= 1 });
28 floor
29 })
30 .with_examples(&["(())", "()()", ")))", ")())())"]);
31
32 // Create a new `Puzzle` instance for part 2
33 let part_2 = Puzzle::new(2, first_instruction_that_sends_to_basement)
34 .with_examples(&[")", "()())"]);
35
36 // Test the example cases
37 day_1.test(&part_1);
38 day_1.test(&part_2);
39 // Run the day's input
40 day_1.run(&part_1).unwrap();
41 day_1.run(&part_2).unwrap();
42}
Sourcepub fn examples<S: ToString>(&mut self, examples: &[S])
pub fn examples<S: ToString>(&mut self, examples: &[S])
Provide some example inputs for a Puzzle
instance that the solver
function will be given when
AocDay::test()
is called.
§Example
use aoc_helper::Puzzle;
let mut part_2 = Puzzle::new(2, |x| x.lines().nth(0).unwrap());
part_2.examples(&["example\ninput", "foo\nbar"]);
Sourcepub fn with_examples<S: ToString>(self, examples: &[S]) -> Self
pub fn with_examples<S: ToString>(self, examples: &[S]) -> Self
Chainable version of Puzzle::examples()
§Example
use aoc_helper::Puzzle;
let part_2 = Puzzle::new(2, |x| lines().nth(0).unwrap())
.with_examples(&["example\ninput", "foo\nbar"]);
Examples found in repository?
examples/2015_day1.rs (line 30)
18fn main() {
19 // NOTE: You need to specify a session ID for this to work
20
21 // Create a new `AocDay` instance for day 1 of aoc 2015
22 let mut day_1 = AocDay::new(2015, 1);
23
24 // Create a new `Puzzle` instance for part 1
25 let part_1 = Puzzle::new(1, |instructions: String| {
26 let mut floor = 0;
27 instructions.chars().for_each(|x| if x == '(' { floor += 1 } else { floor -= 1 });
28 floor
29 })
30 .with_examples(&["(())", "()()", ")))", ")())())"]);
31
32 // Create a new `Puzzle` instance for part 2
33 let part_2 = Puzzle::new(2, first_instruction_that_sends_to_basement)
34 .with_examples(&[")", "()())"]);
35
36 // Test the example cases
37 day_1.test(&part_1);
38 day_1.test(&part_2);
39 // Run the day's input
40 day_1.run(&part_1).unwrap();
41 day_1.run(&part_2).unwrap();
42}
Auto Trait Implementations§
impl<T, D> Freeze for Puzzle<T, D>
impl<T, D> RefUnwindSafe for Puzzle<T, D>
impl<T, D> Send for Puzzle<T, D>
impl<T, D> Sync for Puzzle<T, D>
impl<T, D> Unpin for Puzzle<T, D>
impl<T, D> UnwindSafe for Puzzle<T, D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more