diff --git a/src/main.rs b/src/main.rs index 54f00fd..cd57182 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,8 @@ extern crate rand; fn main() { let size = 100; + + // initialize the boxes with randomly assigned numbers let mut boxes:Vec = Vec::with_capacity(size as usize); { @@ -39,6 +41,7 @@ fn main() { } } + // have prisoners find their number let mut all_found = true; for i in 0..size { @@ -54,10 +57,6 @@ fn main() { else { next_box = boxes[next_box] as usize; - if next_box == i as usize - { - break; - } } } if !found @@ -66,6 +65,7 @@ fn main() { } } + // print result if all_found { println!("All prisoners found their numbers!");