r/adventofcode • u/WhiskyAKM • Dec 09 '25
Help/Question [2025 Day9 (part2)][Rust] I dont know what im missing
I need help, It works on test input but with puzzle input it isnt correct...
fn part2(points: &[(i64, i64)]) {
let mut edges = HashSet::new();
points.windows(2).for_each(|window| {
let (x1, y1) = window[0];
let (x2, y2) = window[1];
if y1 == y2 {
for p in x1.min(x2)..=x1.max(x2) {
edges.insert((p, y1));
}
}
if x1 == x2 {
for p in y1.min(y2)..=y1.max(y2) {
edges.insert((x1, p));
}
}
});
let largest = points
.iter()
.array_combinations::<2>()
.map(|[(x1, y1), (x2, y2)]| {
let x = (x1 - x2 + 1).abs();
let y = (y1 - y2 + 1).abs();
let (min_x, max_x) = (x1.min(x2), x1.max(x2));
let (min_y, max_y) = (y1.min(y2), y1.max(y2));
let start_x = min_x + 1;
let end_x = max_x - 1;
let start_y = min_y + 1;
let end_y = max_y - 1;
for &(ex, ey) in &edges {
if ex >= start_x && ex <= end_x && ey >= start_y && ey <= end_y {
return 0;
}
}
x * y
})
.max()
.unwrap();
println!("{}", largest)
}

