day10 part 2

This commit is contained in:
Johannes
2018-12-11 09:35:19 +01:00
parent 4eb90ac047
commit 6d4bdccc6e

View File

@@ -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 {