@@ -3,30 +3,32 @@ use aoc::util::parse::*;
3
3
use aoc:: * ;
4
4
use std:: env:: args;
5
5
use std:: fs:: read_to_string;
6
- use std:: iter:: empty;
7
6
use std:: time:: { Duration , Instant } ;
8
7
9
8
fn main ( ) {
10
9
// 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 > > ( ) ) ;
14
11
let ( year, day) = ( iter. next ( ) , iter. next ( ) ) ;
15
12
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
+
16
26
// 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 ) )
30
32
. fold ( ( 0 , Duration :: ZERO ) , |( stars, duration) , Solution { year, day, wrapper } | {
31
33
let path = format ! ( "input/year{year}/day{day:02}.txt" ) ;
32
34
@@ -50,7 +52,7 @@ fn main() {
50
52
} ) ;
51
53
52
54
// Optionally print totals.
53
- if args. contains ( & "--totals" ) {
55
+ if args ( ) . any ( |arg| arg == "--totals" ) {
54
56
println ! ( "{BOLD}{YELLOW}⭐ {}{RESET}" , stars) ;
55
57
println ! ( "{BOLD}{WHITE}🕓 {} ms{RESET}" , duration. as_millis( ) ) ;
56
58
}
0 commit comments