Skip to content

Commit 5082353

Browse files
authored
Refine condition for updating minimum path (#17)
Recent change makes the case faster and on a modern CPU it generates unstable results running `cargo test` * pass * fail `thread 'year2016::day17::part1_test' panicked at tests\year2016\day17.rs:8:5` with either one of the following failures * failure 1: left: "DRRULDDULRDLUURLRLDRRURLRLDDRD" right: "DDRRRD" * failrue 2: left: "" right: "DDRRRD" Add a check to the condition.
1 parent a44b026 commit 5082353

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/year2016/day17.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn worker(shared: &Shared) {
6969
let mut state = shared.mutex.lock().unwrap();
7070

7171
// Update min and max paths.
72-
if state.min.is_empty() || local.min.len() < state.min.len() {
72+
if !local.min.is_empty() && (state.min.is_empty() || local.min.len() < state.min.len()) {
7373
state.min.clone_from(&local.min);
7474
}
7575
state.max = state.max.max(local.max);

0 commit comments

Comments
 (0)