day10 part 2
This commit is contained in:
@@ -27,20 +27,22 @@ pub fn task1() {
|
||||
// }
|
||||
|
||||
let mut old_area = get_area(&lights);
|
||||
let mut time = 0;
|
||||
loop {
|
||||
time += 1;
|
||||
let new_lights = lights.iter().map(|light| light.move_copy()).collect();
|
||||
// print_lights(&new_lights);
|
||||
let new_area = get_area(&new_lights);
|
||||
// println!("Area: {} ", new_area);
|
||||
if new_area > old_area {
|
||||
println!("Found a minimum..");
|
||||
print_lights(&lights);
|
||||
break;
|
||||
} else {
|
||||
lights = new_lights;
|
||||
old_area = new_area;
|
||||
}
|
||||
}
|
||||
println!("Found a minimum after {} seconds", time - 1);
|
||||
print_lights(&lights);
|
||||
}
|
||||
|
||||
fn get_area(lights: &Vec<Light>) -> usize {
|
||||
|
||||
Reference in New Issue
Block a user