Skip to content

Instantly share code, notes, and snippets.

@ayazhafiz
Created January 6, 2018 04:31
Show Gist options
  • Save ayazhafiz/fec1b5d60fc4405335ff425e0f8feb2e to your computer and use it in GitHub Desktop.
Save ayazhafiz/fec1b5d60fc4405335ff425e0f8feb2e to your computer and use it in GitHub Desktop.
fn cost(points: &[[f64; 2]], center: &[f64; 2]) -> f64 {
points.iter().fold(0., |net, point| {
let cost = (
(center[0] - point[0]).powi(2) // `x` coordinates
+ (center[1] - point[1]).powi(2) // `y` coordinates
).sqrt();
net + cost
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment