Skip to content

Instantly share code, notes, and snippets.

@krishnanraman
Last active February 2, 2018 21:57
Show Gist options
  • Save krishnanraman/c7e7b33a73379cad0142e7e798b7e579 to your computer and use it in GitHub Desktop.
Save krishnanraman/c7e7b33a73379cad0142e7e798b7e579 to your computer and use it in GitHub Desktop.
// Given 2 points in first quadrant
// Point p1 (a,b)
// Point p2 (c,d)
// a,b,c,d > 0
//
// Find point X(x,0) on x axis
// such that
// ||p1-X|| + ||p2-X|| is smallest
//
def smallest(a:Int, b:Int, c:Int, d:Int) = (a*d + b*c)/(b+d)
x = smallest(a,b,c,d)
// Boom!
// But why ? Hah! It's not that hard...
// But Jesus!
// SV firms should seriously stop with these puzzles for interviews.
// Stop it already!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment