Completed solution.
This commit is contained in:
parent
df21fd2c3f
commit
cd8f4319ab
38
src/main.rs
38
src/main.rs
@ -29,7 +29,7 @@ fn main() {
|
|||||||
let mut boxes:Vec<u32> = Vec::with_capacity(size as usize);
|
let mut boxes:Vec<u32> = Vec::with_capacity(size as usize);
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut nums:Vec<u32> = (1..size+1).collect();
|
let mut nums:Vec<u32> = (0..size).collect();
|
||||||
|
|
||||||
while nums.len() > 0
|
while nums.len() > 0
|
||||||
{
|
{
|
||||||
@ -38,4 +38,40 @@ fn main() {
|
|||||||
nums.remove(rand_i);
|
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!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user