Skip to content

Commit a449cbf

Browse files
committed
Day 20
1 parent 4c63c52 commit a449cbf

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www.
3030
| [Day 17](./src/bin/17.rs) | `1.7µs` | `361.3µs` |
3131
| [Day 18](./src/bin/18.rs) | `49.6µs` | `58.9µs` |
3232
| [Day 19](./src/bin/19.rs) | `204.0µs` | `693.5µs` |
33-
| [Day 20](./src/bin/20.rs) | `325.0µs` | `4.6ms` |
33+
| [Day 20](./src/bin/20.rs) | `307.5µs` | `1.8ms` |
3434

35-
**Total: 19.39ms**
35+
**Total: 16.57ms**
3636
<!--- benchmarking table --->
3737

3838
---

src/bin/20.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ fn dijkstra(grid: &Grid<char>, start: Point, end: Point) -> Grid<i64> {
4949
}
5050

5151
fn 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

Comments
 (0)