Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

dry solution! macro implementation #48

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions src/template/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,23 @@ pub fn read_file_part(folder: &str, day: Day, part: u8) -> String {
#[macro_export]
macro_rules! solution {
($day:expr) => {
/// The current day.
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);
}
$crate::solution!(@impl $day, [part_one, 1] [part_two, 2]);
};
($day:expr, 1) => {
/// Allows solving part one in isolation
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);
}
$crate::solution!(@impl $day, [part_one, 1]);
};
($day:expr, 2) => {
/// Allows solving part two in isolation
const DAY: advent_of_code::template::Day = advent_of_code::day!($day);
$crate::solution!(@impl $day, [part_two, 2]);
};

(@impl $day:expr, $( [$func:expr, $part:expr] )*) => {
/// The current day.
const DAY: $crate::template::Day = $crate::day!($day);

fn main() {
use advent_of_code::template::runner::*;
let input = advent_of_code::template::read_file("inputs", DAY);
run_part(part_two, &input, DAY, 2);
use $crate::template::runner::*;
let input = $crate::template::read_file("inputs", DAY);
$( run_part($func, &input, DAY, $part); )*
}
};
}