@@ -49,6 +49,9 @@ fn dijkstra(grid: &Grid<char>, start: Point, end: Point) -> Grid<i64> {
49
49
}
50
50
51
51
fn solve < const CHEAT_MOVES : isize > ( input : & str , min_gain : i64 ) -> Option < i64 > {
52
+ assert ! ( CHEAT_MOVES > 1 ) ;
53
+ assert ! ( min_gain > 0 ) ;
54
+
52
55
let ( grid, start, end) = parse_input ( input) ;
53
56
let cost = dijkstra ( & grid, start, end) ;
54
57
@@ -76,7 +79,6 @@ fn solve<const CHEAT_MOVES: isize>(input: &str, min_gain: i64) -> Option<i64> {
76
79
. map ( |& ( diff, moves) | ( start_pos + diff, moves) )
77
80
. filter ( |& ( pos, _) | cost. is_in_bounds ( pos) )
78
81
. filter ( |& ( pos, _) | cost[ pos] != i64:: MAX )
79
- . filter ( |& ( pos, moves) | cost[ pos] > start_cost + moves as i64 )
80
82
. filter ( |& ( pos, moves) | cost[ pos] - ( start_cost + moves as i64 ) >= min_gain)
81
83
. count ( ) as i64 ;
82
84
@@ -101,7 +103,7 @@ mod tests {
101
103
#[ test]
102
104
fn test_part_one_0 ( ) {
103
105
let input = advent_of_code:: template:: read_file ( "examples" , DAY ) ;
104
- let result = solve :: < 2 > ( & input, 0 ) ;
106
+ let result = solve :: < 2 > ( & input, 1 ) ;
105
107
assert_eq ! ( result, Some ( 44 ) ) ;
106
108
}
107
109
0 commit comments