diff --git a/src/bin/scaffold.rs b/src/bin/scaffold.rs index e77d39d..e566233 100644 --- a/src/bin/scaffold.rs +++ b/src/bin/scaffold.rs @@ -4,16 +4,18 @@ use std::{ process, }; -const MODULE_TEMPLATE: &str = r###"pub fn part_one(input: &str) -> u32 { - 0 +const MODULE_TEMPLATE: &str = r###"pub fn part_one(input: &str) -> Option { + None } -pub fn part_two(input: &str) -> u32 { - 0 +pub fn part_two(input: &str) -> Option { + None } fn main() { - aoc::solve!(&aoc::read_file("inputs", DAY), part_one, part_two) + let input = &aoc::read_file("inputs", DAY); + aoc::solve!(1, part_one, input); + aoc::solve!(2, part_two, input); } #[cfg(test)] @@ -24,14 +26,14 @@ mod tests { fn test_part_one() { use aoc::read_file; let input = read_file("examples", DAY); - assert_eq!(part_one(&input), 0); + assert_eq!(part_one(&input), None); } #[test] fn test_part_two() { use aoc::read_file; let input = read_file("examples", DAY); - assert_eq!(part_two(&input), 0); + assert_eq!(part_two(&input), None); } } "###; diff --git a/src/lib.rs b/src/lib.rs index 89bd78d..5b85149 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,28 +11,30 @@ pub const ANSI_RESET: &str = "\x1b[0m"; #[macro_export] macro_rules! solve { - ($input:expr, $part_one:ident, $part_two:ident) => {{ + ($part:expr, $solver:ident, $input:expr) => {{ use aoc::{ANSI_BOLD, ANSI_ITALIC, ANSI_RESET}; use std::fmt::Display; use std::time::Instant; - fn print_result(func: impl FnOnce(&str) -> T, input: &str) { + fn print_result(func: impl FnOnce(&str) -> Option, input: &str) { let timer = Instant::now(); let result = func(input); let elapsed = timer.elapsed(); - println!( - "{} {}(elapsed: {:.2?}){}", - result, ANSI_ITALIC, elapsed, ANSI_RESET - ); + match result { + Some(result) => { + println!( + "{} {}(elapsed: {:.2?}){}", + result, ANSI_ITALIC, elapsed, ANSI_RESET + ); + }, + None => { + println!("not solved.") + } + } } - println!("🎄 {}Part 1{} 🎄", ANSI_BOLD, ANSI_RESET); - println!(""); - print_result($part_one, $input); - println!(""); - println!("🎄 {}Part 2{} 🎄", ANSI_BOLD, ANSI_RESET); - println!(""); - print_result($part_two, $input); + println!("🎄 {}Part {}{} 🎄", ANSI_BOLD, $part, ANSI_RESET); + print_result($solver, $input); }}; } diff --git a/src/main.rs b/src/main.rs index 540279e..42f4acd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ fn main() { let output = String::from_utf8(cmd.stdout).unwrap(); let is_empty = output.is_empty(); - println!("{}", if is_empty { "Not solved." } else { &output }); + println!("{}", if is_empty { "Not solved." } else { &output.trim() }); if is_empty { 0_f64