1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
use crate::all_puzzles;
use utils::date::{Day, Year};
// These imports are unused if none of the year features are enabled
#[allow(clippy::allow_attributes, unused_imports)]
use utils::{
input::{InputError, InputType},
Puzzle,
};
/// Represents a wrapper function around a puzzle solution.
///
/// See [`PUZZLES`].
pub type PuzzleFn = fn(&str) -> Result<(String, String), InputError>;
macro_rules! matcher {
($(
$y:literal => $year:ident{$(
$d:literal => $day:ident,
)*}
)*) => {
/// Constant containing each puzzle solution.
///
/// Each puzzle is represented by a tuple of [`Year`], [`Day`] and [`PuzzleFn`], which takes
/// a input string and returns the part 1 and 2 solutions as strings, or an [`InputError`].
///
/// Generated from [`all_puzzles!`].
pub const PUZZLES: &[(Year, Day, PuzzleFn)] = &[$($(
(crate::$year::$day::YEAR, crate::$year::$day::DAY, |input: &str| {
let solution = crate::$year::$day::new(input, InputType::Real)?;
let part1 = solution.part1();
let part2 = solution.part2();
Ok((part1.to_string(), part2.to_string()))
}),
)*)*];
};
}
all_puzzles!(matcher);