diff --git a/src/main.rs b/src/main.rs index 91dcda6..4673916 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,17 +93,16 @@ fn main() }; // the next (first) box the prisoner is to open is the one with his number (`i`) let mut next_box:usize = i as usize; - // for every attempt the prisoner has (i.e. `size/2`) - for _j in 0..(size/2) + // while the prisoner still has attempts left AND he hasn't found his number + while prisoner_i.attempts < size/2 && !prisoner_i.found { + // count attempt prisoner_i.attempts += 1; // if the number inside the box is his number if boxes[next_box] == i { // assign `found` to true prisoner_i.found = true; - // stop looking through more boxes. - break; } else {