Last active
February 2, 2018 21:57
-
-
Save krishnanraman/c7e7b33a73379cad0142e7e798b7e579 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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