@@ -10,8 +10,8 @@ impl Solution for Day22 {
10
10
fn part_one ( & self , input : & str ) -> String {
11
11
input
12
12
. lines ( )
13
- . map ( |line| {
14
- let initial : usize = line . parse ( ) . unwrap ( ) ;
13
+ . map ( |line| line . parse :: < usize > ( ) . unwrap ( ) )
14
+ . map ( |initial| {
15
15
let secrets = self . next_secrets ( initial, SECRET_COUNT ) ;
16
16
17
17
* secrets. last ( ) . unwrap ( )
@@ -25,29 +25,21 @@ impl Solution for Day22 {
25
25
26
26
input. lines ( ) . for_each ( |line| {
27
27
let mut seen_map: HashSet < [ i8 ; 4 ] > = HashSet :: new ( ) ;
28
-
29
28
let initial: usize = line. parse ( ) . unwrap ( ) ;
30
29
let secrets = self . next_secrets ( initial, SECRET_COUNT ) ;
31
30
let prices = self . prices ( secrets) ;
32
31
let diffs = self . diffs ( & prices) ;
33
32
34
- assert_eq ! ( SECRET_COUNT , diffs. len( ) ) ;
35
-
36
- for i in 4 ..=diffs. len ( ) {
33
+ for i in 4 ..diffs. len ( ) {
37
34
let key = [ diffs[ i - 4 ] , diffs[ i - 3 ] , diffs[ i - 2 ] , diffs[ i - 1 ] ] ;
38
35
39
- if seen_map. contains ( & key) {
40
- continue ;
36
+ if seen_map. insert ( key) {
37
+ * map . entry ( key ) . or_insert ( 0 ) += prices [ i ] as usize ;
41
38
}
42
-
43
- * map. entry ( key) . or_insert ( 0 ) += prices[ i] as usize ;
44
- seen_map. insert ( key) ;
45
39
}
46
40
} ) ;
47
41
48
- let max = map. iter ( ) . max_by_key ( |( _, & v) | v) . unwrap ( ) ;
49
-
50
- max. 1 . to_string ( )
42
+ map. values ( ) . max ( ) . unwrap ( ) . to_string ( )
51
43
}
52
44
}
53
45
0 commit comments