Write a program or function that takes in a quadratic equation and prints its factorized roots. The input can be taken in from any reasonable source, such as a function parameter, stdin, or a command line argument.
Edit: This is not intended to be a duplicate of other quadratic equation questions. While others simply provide the integers of the equation and expect integer answers, this question is more about parsing the input string and printing an output string of the exact appropriate form.
Input will be either a string or an array of characters, and it will be of the form
ax^2 + bx + c, where
c are integers. The input will always be exactly of this form, whether the integers are positive, negative, or 0.
Output will be a string (or array of characters) of the form
(x - d)(x - e) where
e are the roots of the equation. You may assume that input will have exactly 2 rational roots.
1x^2 + 6x + 9 =>
(x - -3)(x - -3)
1x^2 + 0x + -16 =>
(x - 4)(x - -4)
3x^2 + -9x + -12 =>
(x - -1)(x - 4)
Note: this last example is not an equality as the factor of 3 is missing. Imaginary bonus points if you include the factor, but it is not necessary.
This is code golf, so shortest answer in bytes wins.
If your submission can handle the following restrictions, your score will be halved.
cin the input are negative, it will be represented with a minus, i.e.
ax^2 + -bx + -cwill instead be represented as
ax^2 - bx - c
care 1, they will be omitted. If they are 0, the whole value will be omitted. i.e.
1x^2 + 0x + -16will be represented as
x^2 - 16
- The same rules apply to output;
x^2 + 5xmust produce exactly
(x)(x + 5)or
(x + 5)(x)