@@ -46,7 +46,7 @@ impl PartialOrd for Node {
46
46
47
47
#[ derive( Clone , Copy , Debug , Hash , PartialEq , Eq ) ]
48
48
enum CheatPolicy {
49
- Allowed ,
49
+ Allowed { picos : i32 } ,
50
50
Forbidden ,
51
51
}
52
52
@@ -96,7 +96,7 @@ impl Racetrack {
96
96
if self . in_bounds ( neigh) {
97
97
let is_wall = self [ neigh] == '#' ;
98
98
99
- let cheats_allowed = cheat_policy == CheatPolicy :: Allowed ;
99
+ let cheats_allowed = matches ! ( cheat_policy, CheatPolicy :: Allowed { .. } ) ;
100
100
let can_cheat = cheats_allowed && node. cheat . map_or ( true , |c| c. picos_left > 0 ) ;
101
101
let new_cheat = if let Some ( cheat) = node. cheat {
102
102
let is_ending = cheat. picos_left == 1 ;
@@ -105,7 +105,11 @@ impl Racetrack {
105
105
}
106
106
Some ( Cheat { start : cheat. start , end : if is_ending { Some ( neigh) } else { cheat. end } , picos_left : ( cheat. picos_left - 1 ) . max ( 0 ) } )
107
107
} else if cheats_allowed && is_wall {
108
- Some ( Cheat { start : node. pos , end : None , picos_left : 1 } )
108
+ if let CheatPolicy :: Allowed { picos : cheat_picos } = cheat_policy {
109
+ Some ( Cheat { start : node. pos , end : None , picos_left : cheat_picos } )
110
+ } else {
111
+ unreachable ! ( )
112
+ }
109
113
} else {
110
114
node. cheat
111
115
} ;
@@ -152,8 +156,11 @@ fn main() {
152
156
let shortest_path = track. find_paths ( start, end, CheatPolicy :: Forbidden , |_| true ) [ 0 ] ;
153
157
let base_picos = shortest_path. picos ;
154
158
155
- let cheat_paths = track. find_paths ( start, end, CheatPolicy :: Allowed , |n| n. picos <= base_picos - 100 ) ;
156
- let part1 = cheat_paths. len ( ) ;
159
+ // let cheat_paths1 = track.find_paths(start, end, CheatPolicy::Allowed { picos: 2 }, |n| n.picos <= base_picos - 100);
160
+ // let part1 = cheat_paths1.len();
161
+ // println!("Part 1: {part1}");
157
162
158
- println ! ( "Part 1: {part1}" ) ;
163
+ let cheat_paths2 = track. find_paths ( start, end, CheatPolicy :: Allowed { picos : 20 } , |n| n. picos <= base_picos - 100 ) ;
164
+ let part2 = cheat_paths2. len ( ) ;
165
+ println ! ( "Part 2: {part2}" ) ;
159
166
}
0 commit comments