From 22add1bf09ec15866d726e53573a0a321ce9590a Mon Sep 17 00:00:00 2001 From: Kevin Caffrey Date: Sat, 23 Dec 2023 15:35:16 -0500 Subject: [PATCH] clean up old code where I stored the path for debugging purposes --- README.md | 4 ++-- src/bin/23.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 881a070..f82bfa8 100644 --- a/README.md +++ b/README.md @@ -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) | `329.1µs` | `72.6ms` | +| [Day 23](./src/bin/23.rs) | `328.8µs` | `69.4ms` | -**Total: 89.54ms** +**Total: 86.34ms** --- diff --git a/src/bin/23.rs b/src/bin/23.rs index 744eb39..82c4e60 100644 --- a/src/bin/23.rs +++ b/src/bin/23.rs @@ -41,8 +41,8 @@ pub fn part_two(input: &str) -> Option { goal = new_goal; } - let mut visited = vec![None; graph.vertices]; - visited[start] = Some(0); + let mut visited = vec![false; graph.vertices]; + visited[start] = true; Some(trimmed_length + part_two_recursive_brute_force(&graph, start, goal, &mut visited, 0)) } @@ -50,7 +50,7 @@ fn part_two_recursive_brute_force( graph: &Graph, cur: usize, goal: usize, - visited: &mut [Option], + visited: &mut [bool], so_far: u16, ) -> u16 { if cur == goal { @@ -59,12 +59,12 @@ fn part_two_recursive_brute_force( let mut max = 0; for &(neighbor, cost) in &graph.adjacency[cur] { - if visited[neighbor].is_none() { - visited[neighbor] = Some(cur); + if !visited[neighbor] { + visited[neighbor] = true; let next_so_far = part_two_recursive_brute_force(graph, neighbor, goal, visited, so_far + cost); max = max.max(next_so_far); - visited[neighbor] = None; + visited[neighbor] = false; } }