code cleanup for part2

master
attila 4 years ago
parent d98b679967
commit 2eb8adf620

@ -53,24 +53,20 @@ fn intersecting_area(rectangles: &Vec<Rectangle>) -> i32 {
return intersects.values().filter(|i| **i > 1).count() as i32;
}
fn not_intersecting_claim(rectangles: &Vec<Rectangle>) -> Result<i32, std::io::Error>
fn not_intersecting_claim(rectangles: &[Rectangle]) -> Result<i32, &str>
{
for i in 0..rectangles.len() {
let mut found = true;
for j in 0..rectangles.len() {
if rectangles_intersecting(&rectangles[i], &rectangles[j]) && i != j {
found = false;
break;
'outer:
for rect1 in rectangles.iter() {
for rect2 in rectangles.iter() {
if rect1.id != rect2.id && rectangles_intersecting(&rect1, &rect2) {
continue 'outer;
}
}
}
if found {
return Ok(rectangles[i].id.clone());
return Ok(rect1.id.clone());
}
}
return Err(std::io::Error::new(std::io::ErrorKind::Other, "No not intersecting claim found"))
Err("No not intersecting claim found")
}
fn rectangles_intersecting(r1: &Rectangle, r2: &Rectangle) -> bool {

Loading…
Cancel
Save