diff --git a/src/main.rs b/src/main.rs index cd35bef..54f00fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ fn main() { let mut boxes:Vec = Vec::with_capacity(size as usize); { - let mut nums:Vec = (1..size+1).collect(); + let mut nums:Vec = (0..size).collect(); while nums.len() > 0 { @@ -38,4 +38,40 @@ fn main() { nums.remove(rand_i); } } + + let mut all_found = true; + for i in 0..size + { + let mut next_box:usize = i as usize; + let mut found = false; + for _j in 0..(size/2) + { + if boxes[next_box] == i + { + found = true; + break; + } + else + { + next_box = boxes[next_box] as usize; + if next_box == i as usize + { + break; + } + } + } + if !found + { + all_found = false; + } + } + + if all_found + { + println!("All prisoners found their numbers!"); + } + else + { + println!("Some prisoners didn't find their numbers!"); + } }