challenge
Four integers A, B, C and D are given. The integers can be used to describe two points on a plane by assigning their values to the coordinates of the points. Each integer has to be assigned to exactly one coordinate. Your task is to assign the integers A, B, C and D to the coordinates of two points in such a way as to maximize the squared distance between those points.
For example, let's consider the following values:
A = 1
B = 1
C = 2
D = 3
One way is to create two points (A, D) and (B, C) as shown below:
The squared distance between the chosen points is equal to 1. Another way would be to create points (A, C) and (D, B):
Write a function that, given four integers A, B, C and D, returns the maximum possible squared distance between two points that can be plotted with those integers.
For example, given input:
A = 1 B = 1 C = 2 D = 3
your function should return 5, as explained above. Given:
A = 2 B = 4 C = 2 D = 4
the function should return 8. This value can be achieved by choosing points (A, C) and (B, D), as shown below:
Note that the four integers supplied as input are not necessarily distinct or sorted.
Assume that A, B, C and D are integers within the range [-5,000..5,000]