Due to the rise of covid-19 cases in India, this year BCCI decided to organize knock-out matches in IPL rather than a league. 
Today is matchday 1 and it is between previous year winners Mumbai Indians and the city of Joy - Kolkata Knight Riders. Eoin Morgan the new captain of the team KKR, thinks that death overs are very important to win a match. He decided to end MI's innings with his most trusted bowler Pat Cummins to minimize the target. There must be at least 4 players inside the 30-yard circle in death overs. Positions of 3 players are already decided which are given as 2-D integer points A, B, and C,  the task is to find the missing point D such that ABCD should be a parallelogram. If there are multiple such points, find the lexicographically smallest coordinate.
 
Example 1:
Input:
A = (3, 2)
B = (3, 4)
c = (2, 2)
Output:
2.000000 0.000000
Explanation: There are two options for 
point D : (2, 4) and (2, 0) such that ABCD 
forms a parallelogram. Since (2, 0) is 
lexicographically smaller than (2, 4). Hence,
(2, 0) is the answer.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findPoint() which takes three lists of integers A[], B[] and C[] and return D[] list of two numbers with a precision of 6 decimal places where first element of D[ ] denote x coordinate and second element of D[ ] denote y coordinate.
Constraints:
1 ≤ x, y ≤ 1000, where x and y denote coordinates of points A, B, and C.
The order of points in the parallelogram doesnt matter.
The given points are not collinear.

Source: geeksforgeeks | Difficulty: MEDIUM
Tags: Geometry

Mathematics

Starter code: #User function Template for python3





class Solution:

    def findPoint(self, A, B, C):

        # code here

Solutions:
class Solution:

	def findPoint(self, a, b, c):
		dx = b[0] - c[0]
		dy = b[1] - c[1]
		ans = [(a[0] + dx, a[1] + dy), (a[0] - dx, a[1] - dy)]
		dx = a[0] - b[0]
		dy = a[1] - b[1]
		ans += [(c[0] + dx, c[1] + dy), (c[0] - dx, c[1] - dy)]
		return min(ans)


class Solution:

	def orderLex(self, a, b, c):
		winners = [a]
		if b[0] < winners[0][0]:
			winners = [b]
		elif b[0] == winners[0][0]:
			winners.append(b)
		if c[0] == winners[0][0]:
			winners.append(c)
		elif c[0] < winners[0][0]:
			winners[0] = c
		return min(winners, key=lambda t: t[1])

	def newPoint(self, A, B, C):
		return (C[0] - B[0] + A[0], C[1] - B[1] + A[1])

	def findPoint(self, A, B, C):
		(a, b, c) = (self.newPoint(A, B, C), self.newPoint(B, C, A), self.newPoint(C, A, B))
		return self.orderLex(a, b, c)


class Solution:

	def findPoint(self, A, B, C):
		P = [A[0] + C[0] - B[0], A[1] + C[1] - B[1]]
		Q = [B[0] + C[0] - A[0], B[1] + C[1] - A[1]]
		R = [A[0] + B[0] - C[0], A[1] + B[1] - C[1]]
		X = min(P[0], Q[0], R[0])
		if P[0] == X:
			if Q[0] == X:
				if P[1] > Q[1]:
					return Q
			elif R[0] == X:
				if P[1] > R[1]:
					return R
			return P
		elif Q[0] == X:
			if R[0] == X and Q[1] > R[1]:
				return R
			return Q
		return R