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