Skip to content

Instantly share code, notes, and snippets.

View mszarski's full-sized avatar

Martin Szarski mszarski

  • Melbourne, Australia
View GitHub Profile
@mszarski
mszarski / closestPair.fs
Created December 30, 2010 08:56
Closest Pair of Points solution in F#
let dist (x1,y1) (x2,y2) =
Math.Sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
let closestBf points =
let n = Seq.length points
let list = points |> Seq.toList
seq { for i in 0..n-2 do
for j in i+1..n-1 do
yield list.[i], list.[j] }
|> Seq.minBy (fun (a, b) -> dist a b)