Skip to content

Commit

Permalink
more correct is a random shuffling of the vertices, otherwise an evil…
Browse files Browse the repository at this point in the history
… input could make us go slow
  • Loading branch information
kcaffrey committed Dec 26, 2023
1 parent 0c455af commit 18effe2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ tinyvec = "1.6.0"
fxhash = "0.2.1"
ndarray = "0.15.6"
ndarray-linalg = { version = "0.16.0", features = ["openblas-static"] }
rand = "0.8.5"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www.
| [Day 22](./src/bin/22.rs) | `78.3µs` | `194.8µs` |
| [Day 23](./src/bin/23.rs) | `330.4µs` | `13.3ms` |
| [Day 24](./src/bin/24.rs) | `257.2µs` | `16.2µs` |
| [Day 25](./src/bin/25.rs) | `239.4µs` | `-` |
| [Day 25](./src/bin/25.rs) | `256.4µs` | `-` |

**Total: 30.75ms**
**Total: 30.77ms**
<!--- benchmarking table --->

---
Expand Down
7 changes: 6 additions & 1 deletion src/bin/25.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use std::collections::VecDeque;

use fxhash::FxHashMap;
use rand::{seq::SliceRandom, thread_rng};

advent_of_code::solution!(25, 1);

pub fn part_one(input: &str) -> Option<usize> {
let mut flow: NetworkFlow = parse_graph(input).into();
let s = 0;
(1..flow.vertices).find_map(|t| find_cut_of_size(&mut flow, s, t, 3))
let mut vertices = (1..flow.vertices).collect::<Vec<_>>();
vertices.shuffle(&mut thread_rng());
vertices
.into_iter()
.find_map(|t| find_cut_of_size(&mut flow, s, t, 3))
}

fn find_cut_of_size(net: &mut NetworkFlow, s: usize, t: usize, cut: i16) -> Option<usize> {
Expand Down

0 comments on commit 18effe2

Please sign in to comment.