This problem actually came up in a topic a while back --> The combinatorics of a permutation
"
.
.
.
Now, the tricky math part.
Using the values of MIN, MAX, SUM, and PRODUCT we can find the values of X_LOW and X_HIGH.
Taking the SUM of W, X, Y, and Z, if we subtract the values of MIN and MAX we are left with the sum of the two middle numbers X_LOW and X_HIGH.
Sum of X_LOW and X_HIGH: n = SUM - MIN - MAX
Taking the PRODUCT of W, X, Y, and Z, if we divide out the values of MIN and MAX we are left with the product of the two middle numbers X_LOW and X_HIGH.
Product of X_LOW and X_HIGH: m = PRODUCT / (MIN * MAX)
At this point, we still don't know the values of X_LOW and X_HIGH.
However, the values can be represented as lowercase x and y.
It does not matter which is X_LOW or X_HIGH.
We can represent the sum of X_LOW and X_HIGH as: x + y
We can also represent the product of X_LOW and X_HIGH as: xy
Sum of X_LOW and X_HIGH: n = x + y
Product of X_LOW and X_HIGH: m = xy
We now use these equations to solve for one of the variables, preferably x.
First, isolate y in the sum equation.
n = x + y
n - x = x + y - x
n - x = y
y = n - x
Next, substitute the value of y into the product equation.
m = xy
m = x( n - x )
m = nx - xx
m = nx - x2
You math geeks should see this is a Quadratic Equation.
Now, put the Quadratic Equation in Standard Form, ax2 + bx + c = 0.
-( nx - x2 ) + m = nx - x2 - ( nx - x2 )
x2 - nx + m = nx - x2 - nx + x2
x2 - nx + m = 0
From the Quadratic Equation in Standard From, we see that a = 1, b = -n, and c = m.
Using the Quadratic Formula, we can solve for x.
-b ± √ b2 - 4ac
Quadratic Formula: x = ---------------
2a
-(-n) ± √ (-n)2 - 4(1)(m)
x = -------------------------
2(1)
n ± √ n2 - 4m
x = -------------
2
The values of x are the two roots of the Quadratic Equation, this occurs from the ± symbol.
The ± symbol can also determine the X_LOW and X_HIGH values.
n - √ n2 - 4m
The X_LOW value is: x = -------------
2
n + √ n2 - 4m
The X_HIGH value is: x = -------------
2
We can now substitute the values of n and m from the previous equations n = SUM - MIN - MAX and m = PRODUCT / (MIN * MAX).
(SUM - MIN - MAX) - √ (SUM - MIN - MAX)2 - 4(PRODUCT / (MIN * MAX))
The X_LOW value is: x = -------------------------------------------------------------------
2
(SUM - MIN - MAX) + √ (SUM - MIN - MAX)2 - 4(PRODUCT / (MIN * MAX))
The X_HIGH value is: x = -------------------------------------------------------------------
2
As you can see, if MIN is a zero, dividing the PRODUCT by zero leads to an error.
However, because we have added a one to the numbers, we avoid getting an error and can less the values of X_LOW and X_HIGH by one to get the PICK 4 numbers.
Continues
.
.
.
"