diff --git a/README.md b/README.md index 853c185..ad31bb6 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www. | [Day 16](./src/bin/16.rs) | `58.3µs` | `1.7ms` | | [Day 17](./src/bin/17.rs) | `1.6ms` | `3.7ms` | | [Day 18](./src/bin/18.rs) | `2.4µs` | `2.5µs` | -| [Day 19](./src/bin/19.rs) | `165.3µs` | `642.5µs` | +| [Day 19](./src/bin/19.rs) | `167.5µs` | `616.8µs` | -**Total: 14.89ms** +**Total: 14.86ms** --- diff --git a/src/bin/19.rs b/src/bin/19.rs index 04661e7..bf84a24 100644 --- a/src/bin/19.rs +++ b/src/bin/19.rs @@ -35,12 +35,12 @@ pub fn part_two(input: &str) -> Option { .map(|w| (w.name, w)) .collect::>(); - // BFS until we find accept nodes. Each path to an accept node results + // DFS until we find accept nodes. Each path to an accept node results // in a volume of possible ratings. The union of those volumes is our answer. - let mut queue = VecDeque::new(); - queue.push_back(("in", PartFilter::new(1, 4000))); - let mut accept_volumes = Vec::new(); - while let Some((cur, filter)) = queue.pop_front() { + let mut stack = Vec::with_capacity(1000); + stack.push(("in", PartFilter::new(1, 4000))); + let mut accept_volumes = Vec::with_capacity(1000); + while let Some((cur, filter)) = stack.pop() { let workflow = &workflows[cur]; let mut workflow_filter = Some(filter); for rule in &workflow.rules { @@ -49,7 +49,7 @@ pub fn part_two(input: &str) -> Option { { match rule.destination { Destination::Accept => accept_volumes.push(new_filter), - Destination::Next(d) => queue.push_back((d, new_filter)), + Destination::Next(d) => stack.push((d, new_filter)), Destination::Reject => {} } } @@ -62,7 +62,7 @@ pub fn part_two(input: &str) -> Option { if let Some(filter) = workflow_filter { match workflow.default_rule { Destination::Accept => accept_volumes.push(filter), - Destination::Next(d) => queue.push_back((d, filter)), + Destination::Next(d) => stack.push((d, filter)), Destination::Reject => {} } }