From 94352449dcbb265f297a114ab86e9ae413d5fcf2 Mon Sep 17 00:00:00 2001 From: Song Li Date: Tue, 16 Dec 2025 17:27:41 +0800 Subject: [PATCH] Refine condition for updating minimum path 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. --- src/year2016/day17.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/year2016/day17.rs b/src/year2016/day17.rs index 1c188da..af12bb7 100644 --- a/src/year2016/day17.rs +++ b/src/year2016/day17.rs @@ -69,7 +69,7 @@ fn worker(shared: &Shared) { let mut state = shared.mutex.lock().unwrap(); // Update min and max paths. - if state.min.is_empty() || local.min.len() < state.min.len() { + if !local.min.is_empty() && (state.min.is_empty() || local.min.len() < state.min.len()) { state.min.clone_from(&local.min); } state.max = state.max.max(local.max);