refactor: dry solution!
macro implementation (#48)
This commit is contained in:
parent
a79ce7ad6d
commit
62bb12cb19
1 changed files with 11 additions and 22 deletions
|
@ -39,34 +39,23 @@ pub fn read_file_part(folder: &str, day: Day, part: u8) -> String {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! solution {
|
macro_rules! solution {
|
||||||
($day:expr) => {
|
($day:expr) => {
|
||||||
/// The current day.
|
$crate::solution!(@impl $day, [part_one, 1] [part_two, 2]);
|
||||||
const DAY: advent_of_code::template::Day = advent_of_code::day!($day);
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
use advent_of_code::template::runner::*;
|
|
||||||
let input = advent_of_code::template::read_file("inputs", DAY);
|
|
||||||
run_part(part_one, &input, DAY, 1);
|
|
||||||
run_part(part_two, &input, DAY, 2);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
($day:expr, 1) => {
|
($day:expr, 1) => {
|
||||||
/// Allows solving part one in isolation
|
$crate::solution!(@impl $day, [part_one, 1]);
|
||||||
const DAY: advent_of_code::template::Day = advent_of_code::day!($day);
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
use advent_of_code::template::runner::*;
|
|
||||||
let input = advent_of_code::template::read_file("inputs", DAY);
|
|
||||||
run_part(part_one, &input, DAY, 1);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
($day:expr, 2) => {
|
($day:expr, 2) => {
|
||||||
/// Allows solving part two in isolation
|
$crate::solution!(@impl $day, [part_two, 2]);
|
||||||
const DAY: advent_of_code::template::Day = advent_of_code::day!($day);
|
};
|
||||||
|
|
||||||
|
(@impl $day:expr, $( [$func:expr, $part:expr] )*) => {
|
||||||
|
/// The current day.
|
||||||
|
const DAY: $crate::template::Day = $crate::day!($day);
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
use advent_of_code::template::runner::*;
|
use $crate::template::runner::*;
|
||||||
let input = advent_of_code::template::read_file("inputs", DAY);
|
let input = $crate::template::read_file("inputs", DAY);
|
||||||
run_part(part_two, &input, DAY, 2);
|
$( run_part($func, &input, DAY, $part); )*
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue