@@ -49,6 +49,9 @@ fn dijkstra(grid: &Grid<char>, start: Point, end: Point) -> Grid<i64> {
4949}
5050
5151fn solve < const CHEAT_MOVES : isize > ( input : & str , min_gain : i64 ) -> Option < i64 > {
52+ assert ! ( CHEAT_MOVES > 1 ) ;
53+ assert ! ( min_gain > 0 ) ;
54+
5255 let ( grid, start, end) = parse_input ( input) ;
5356 let cost = dijkstra ( & grid, start, end) ;
5457
@@ -76,7 +79,6 @@ fn solve<const CHEAT_MOVES: isize>(input: &str, min_gain: i64) -> Option<i64> {
7679 . map ( |& ( diff, moves) | ( start_pos + diff, moves) )
7780 . filter ( |& ( pos, _) | cost. is_in_bounds ( pos) )
7881 . filter ( |& ( pos, _) | cost[ pos] != i64:: MAX )
79- . filter ( |& ( pos, moves) | cost[ pos] > start_cost + moves as i64 )
8082 . filter ( |& ( pos, moves) | cost[ pos] - ( start_cost + moves as i64 ) >= min_gain)
8183 . count ( ) as i64 ;
8284
@@ -101,7 +103,7 @@ mod tests {
101103 #[ test]
102104 fn test_part_one_0 ( ) {
103105 let input = advent_of_code:: template:: read_file ( "examples" , DAY ) ;
104- let result = solve :: < 2 > ( & input, 0 ) ;
106+ let result = solve :: < 2 > ( & input, 1 ) ;
105107 assert_eq ! ( result, Some ( 44 ) ) ;
106108 }
107109
0 commit comments