@@ -3,30 +3,32 @@ use aoc::util::parse::*;
33use aoc:: * ;
44use std:: env:: args;
55use std:: fs:: read_to_string;
6- use std:: iter:: empty;
76use std:: time:: { Duration , Instant } ;
87
98fn main ( ) {
109 // Parse command line options
11- let args: Vec < _ > = args ( ) . collect ( ) ;
12- let args: Vec < _ > = args. iter ( ) . map ( String :: as_str) . collect ( ) ;
13- let mut iter = args. iter ( ) . flat_map ( |arg| arg. iter_unsigned :: < u32 > ( ) ) ;
10+ let mut iter = args ( ) . flat_map ( |arg| arg. as_str ( ) . iter_unsigned ( ) . collect :: < Vec < u32 > > ( ) ) ;
1411 let ( year, day) = ( iter. next ( ) , iter. next ( ) ) ;
1512
13+ let solutions = [
14+ year2015 ( ) ,
15+ year2016 ( ) ,
16+ year2017 ( ) ,
17+ year2018 ( ) ,
18+ year2019 ( ) ,
19+ year2020 ( ) ,
20+ year2021 ( ) ,
21+ year2022 ( ) ,
22+ year2023 ( ) ,
23+ year2024 ( ) ,
24+ ] ;
25+
1626 // Filter solutions then pretty print output.
17- let ( stars, duration) = empty ( )
18- . chain ( year2015 ( ) )
19- . chain ( year2016 ( ) )
20- . chain ( year2017 ( ) )
21- . chain ( year2018 ( ) )
22- . chain ( year2019 ( ) )
23- . chain ( year2020 ( ) )
24- . chain ( year2021 ( ) )
25- . chain ( year2022 ( ) )
26- . chain ( year2023 ( ) )
27- . chain ( year2024 ( ) )
28- . filter ( |solution| year. is_none_or ( |y| y == solution. year ) )
29- . filter ( |solution| day. is_none_or ( |d| d == solution. day ) )
27+ let ( stars, duration) = solutions
28+ . into_iter ( )
29+ . flatten ( )
30+ . filter ( |s| year. is_none_or ( |y| y == s. year ) )
31+ . filter ( |s| day. is_none_or ( |d| d == s. day ) )
3032 . fold ( ( 0 , Duration :: ZERO ) , |( stars, duration) , Solution { year, day, wrapper } | {
3133 let path = format ! ( "input/year{year}/day{day:02}.txt" ) ;
3234
@@ -50,7 +52,7 @@ fn main() {
5052 } ) ;
5153
5254 // Optionally print totals.
53- if args. contains ( & "--totals" ) {
55+ if args ( ) . any ( |arg| arg == "--totals" ) {
5456 println ! ( "{BOLD}{YELLOW}⭐ {}{RESET}" , stars) ;
5557 println ! ( "{BOLD}{WHITE}🕓 {} ms{RESET}" , duration. as_millis( ) ) ;
5658 }
0 commit comments