fn find_closest(position: Point, other_points: &[Point]) -> Option<Point> {
    let distances: Vec<i32> = other_points
        .iter()
        .map(|&p| manhattan(position, p))
        .collect();
    let shortest = *distances.iter().min()?;

    let closest_points: Vec<Point> = other_points
        .iter()
        .zip(distances.iter())
        .filter_map(|(&point, &distance)| {
            if distance == shortest {
                Some(point)
            } else {
                None
            }
        })
        .collect();

    if closest_points.len() == 1 {
        Some(closest_points[0])
    } else {
        None
    }
}
/// Finds the closest point to the given coordinates, if there is a unique answer.
/// Returns None if there is a tie.
Finds the closest point to the given coordinates, if there is a unique answer.
Returns None if there is a tie.
Finds the closest point to the given coordinates if there is a unique answer . Returns None if there is a tie .
fn find_closest(position: Point, other_points: &[Point]) -> Option<Point> {
    let distances: Vec<i32> = other_points
        .iter()
        .map(|&p| manhattan(position, p))
        .collect();
    let shortest = *distances.iter().min()?;
    let closest_points: Vec<Point> = other_points
        .iter()
        .zip(distances.iter())
        .filter_map(|(&point, &distance)| {
            if distance == shortest {
                Some(point)
            } else {
                None
            }
        })
        .collect();
    if closest_points.len() == 1 {
        Some(closest_points[0])
    } else {
        None
    }
}
fn find_closest ( position : Point , other_points : & [ Point ] ) -> Option < Point > { let distances : Vec < i32 > = other_points . iter ( ) . map ( | & p | manhattan ( position , p ) ) . collect ( ) ; let shortest = * distances . iter ( ) . min ( ) ? ; let closest_points : Vec < Point > = other_points . iter ( ) . zip ( distances . iter ( ) ) . filter_map ( | ( & point , & distance ) | { if distance == shortest { Some ( point ) } else { None } } ) . collect ( ) ; if closest_points . len ( ) == 1 { Some ( closest_points [ 0 ] ) } else { None } }
Finds the closest point to the given coordinates, if there is a unique answer.
Finds the closest point to the given coordinates if there is a unique answer .
position
Point
other_points
&[Point]
position
Point
other_points
&[Point]