Skip to content

Commit

Permalink
small optimization to day 23
Browse files Browse the repository at this point in the history
  • Loading branch information
kcaffrey committed Dec 23, 2023
1 parent e3ebe03 commit a7bdc42
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www.
| [Day 20](./src/bin/20.rs) | `323.9µs` | `1.2ms` |
| [Day 21](./src/bin/21.rs) | `64.1µs` | `494.7µs` |
| [Day 22](./src/bin/22.rs) | `78.3µs` | `194.8µs` |
| [Day 23](./src/bin/23.rs) | `328.1µs` | `249.8ms` |
| [Day 23](./src/bin/23.rs) | `328.2µs` | `132.8ms` |

**Total: 266.74ms**
**Total: 149.74ms**
<!--- benchmarking table --->

---
Expand Down
5 changes: 1 addition & 4 deletions src/bin/23.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn part_two_recursive_brute_force(
}

let mut max = 0;
for (neighbor, cost) in graph.adjacency[cur] {
for &(neighbor, cost) in &graph.adjacency[cur] {
if visited[neighbor].is_none() {
visited[neighbor] = Some(cur);
let next_so_far =
Expand All @@ -71,7 +71,6 @@ fn build_graph(input: &str, obey_slopes: bool) -> (Graph, usize, usize) {
let goal = Coordinate::new(height - 1, width - 2);
let mut visited = vec![None; width * height];
visited[1] = Some(0);
graph.debug_vertices.push(start);
graph.vertices = 1;
graph.adjacency.resize_with(1, ArrayVec::default);
let mut stack = vec![(0, start, Coordinate::new(0, 0))];
Expand Down Expand Up @@ -140,7 +139,6 @@ fn build_graph(input: &str, obey_slopes: bool) -> (Graph, usize, usize) {
idx
} else {
let idx = graph.vertices;
graph.debug_vertices.push(next_vertex);
graph.vertices += 1;
graph
.adjacency
Expand All @@ -161,7 +159,6 @@ fn build_graph(input: &str, obey_slopes: bool) -> (Graph, usize, usize) {

#[derive(Debug, Default, Clone)]
struct Graph {
debug_vertices: Vec<Coordinate>,
vertices: usize,
adjacency: Vec<ArrayVec<[(usize, u16); 4]>>,
}
Expand Down

0 comments on commit a7bdc42

Please sign in to comment.