Skip to content

Instantly share code, notes, and snippets.

@eribeiro
Last active December 21, 2015 16:49
Show Gist options
  • Save eribeiro/6336560 to your computer and use it in GitHub Desktop.
Save eribeiro/6336560 to your computer and use it in GitHub Desktop.
val arr = Array(2, 4, 5, 19, 21, 28)
val sl = arr.toList.sorted
val dist = sl flatMap { x =>
sl flatMap { y =>
if (x != y) {
if (x < y) List(y - x)
else List(x - y)
}
else Nil
}
}
// minimum distance
dist.min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment