22macro_rules! run_day {
33 (
44 { $i: expr, $curr_day: expr, $year: expr, $opt: expr } ,
5- { day $day: ident { $gen: tt { $( { sol $solution : ident } ) * } } }
5+ { day $day: ident { $gen: tt { $( $sol : tt ) * } } }
66 ) => { {
77 use $crate:: colored:: * ;
88
@@ -26,25 +26,9 @@ macro_rules! run_day {
2626 } ;
2727
2828 if let Some ( input) = $crate:: run_gen!( $day, & data, $gen) {
29- $( {
30- let start = Instant :: now( ) ;
31- let response = $day:: $solution( & input) ;
32- let elapsed = start. elapsed( ) ;
33-
34- $crate:: print_with_duration(
35- stringify!( $solution) ,
36- Some ( format!( "{}" , response) . normal( ) ) ,
37- Some ( elapsed) ,
38- ) ;
39- } ) +
29+ $( $crate:: run_sol!( $day, & input, $sol) ; ) +
4030 } else {
41- $( {
42- $crate:: print_with_duration(
43- stringify!( $solution) ,
44- Some ( "skipped" . dimmed( ) ) ,
45- None ,
46- ) ;
47- } ) +
31+ $( $crate:: skip_sol!( $sol) ; ) +
4832 }
4933 }
5034 } }
@@ -87,3 +71,49 @@ macro_rules! run_gen {
8771 }
8872 } } ;
8973}
74+
75+ #[ macro_export]
76+ macro_rules! run_sol {
77+ // Run solution
78+ ( $day: ident, $input: expr, { sol $solution: ident } ) => { {
79+ let start = Instant :: now( ) ;
80+ let response = $day:: $solution( $input) ;
81+ let elapsed = start. elapsed( ) ;
82+
83+ $crate:: print_with_duration(
84+ stringify!( $solution) ,
85+ Some ( format!( "{}" , response) . normal( ) ) ,
86+ Some ( elapsed) ,
87+ ) ;
88+ } } ;
89+
90+ // Run fallible solution
91+ ( $day: ident, $input: expr, { sol_fallible $solution: ident } ) => { {
92+ use $crate:: colored:: * ;
93+ use $crate:: try_unwrap:: TryUnwrap ;
94+
95+ let start = Instant :: now( ) ;
96+ let response = $day:: $solution( $input) ;
97+ let elapsed = start. elapsed( ) ;
98+
99+ match response. try_unwrap( ) {
100+ Ok ( response) => {
101+ $crate:: print_with_duration(
102+ stringify!( $solution) ,
103+ Some ( format!( "{}" , response) . normal( ) ) ,
104+ Some ( elapsed) ,
105+ ) ;
106+ }
107+ Err ( msg) => {
108+ $crate:: print_with_duration( stringify!( $solution) , Some ( msg. red( ) ) , Some ( elapsed) ) ;
109+ }
110+ }
111+ } } ;
112+ }
113+
114+ #[ macro_export]
115+ macro_rules! skip_sol {
116+ ( { $kind: tt $solution: ident } ) => { {
117+ $crate:: print_with_duration( stringify!( $solution) , Some ( "skipped" . dimmed( ) ) , None ) ;
118+ } } ;
119+ }
0 commit comments