Find the original coordinates whose Manhattan distances are given | Function to find the original coordinated ; Maximum of the given distances ; Sum of the given distances ; Conditions when the solution doesn 't exist ; First coordinate ; Second coordinate ; Third coordinate ; Driver code
function solve ( d1 , d2 , d3 ) { let maxx = Math . max ( d1 , Math . max ( d2 , d3 ) ) ; let sum = ( d1 + d2 + d3 ) ; if ( 2 * maxx > sum sum % 2 == 1 ) { document . write ( " " ) ; return ; } let x1 = 0 , y1 = 0 ; let x2 = d1 , y2 = 0 ; let x3 = parseInt ( ( d1 + d2 - d3 ) / 2 ) ; let y3 = parseInt ( ( d2 + d3 - d1 ) / 2 ) ; document . write ( " " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + x3 + " " + y3 + " " ) ; } let d1 = 3 , d2 = 4 , d3 = 5 ; solve ( d1 , d2 , d3 ) ;