@@ -10,8 +10,8 @@ impl Solution for Day22 {
1010 fn part_one ( & self , input : & str ) -> String {
1111 input
1212 . lines ( )
13- . map ( |line| {
14- let initial : usize = line . parse ( ) . unwrap ( ) ;
13+ . map ( |line| line . parse :: < usize > ( ) . unwrap ( ) )
14+ . map ( |initial| {
1515 let secrets = self . next_secrets ( initial, SECRET_COUNT ) ;
1616
1717 * secrets. last ( ) . unwrap ( )
@@ -25,29 +25,21 @@ impl Solution for Day22 {
2525
2626 input. lines ( ) . for_each ( |line| {
2727 let mut seen_map: HashSet < [ i8 ; 4 ] > = HashSet :: new ( ) ;
28-
2928 let initial: usize = line. parse ( ) . unwrap ( ) ;
3029 let secrets = self . next_secrets ( initial, SECRET_COUNT ) ;
3130 let prices = self . prices ( secrets) ;
3231 let diffs = self . diffs ( & prices) ;
3332
34- assert_eq ! ( SECRET_COUNT , diffs. len( ) ) ;
35-
36- for i in 4 ..=diffs. len ( ) {
33+ for i in 4 ..diffs. len ( ) {
3734 let key = [ diffs[ i - 4 ] , diffs[ i - 3 ] , diffs[ i - 2 ] , diffs[ i - 1 ] ] ;
3835
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 ;
4138 }
42-
43- * map. entry ( key) . or_insert ( 0 ) += prices[ i] as usize ;
44- seen_map. insert ( key) ;
4539 }
4640 } ) ;
4741
48- let max = map. iter ( ) . max_by_key ( |( _, & v) | v) . unwrap ( ) ;
49-
50- max. 1 . to_string ( )
42+ map. values ( ) . max ( ) . unwrap ( ) . to_string ( )
5143 }
5244}
5345
0 commit comments